Node-fs-extra: Feature request: Provide created path for fs.ensure*()

Created on 3 Feb 2017  路  8Comments  路  Source: jprichardson/node-fs-extra

It would in some cases be useful to get feedback at which point an fs.ensure*() method did start to create a folder structure.

Two examples will probably clarify this best:

// Existing path: /my/example/path

// Example 1
fs.ensureDir('/my/example/path/with/some/additions', function (err, created) {
  assert(created === '/my/example/path/with')
})

// Example 2
fs.ensureDir('/my/example', function (err, created) {
  assert(created === null)
})

My concrete use case is that I have to run fs.ensureDir() with root privileges and then set the owner back to the user who ran the command.

enhancement wont-fix

All 8 comments

@jprichardson What do you think? Is this in scope for the project? Can it be implemented without rewriting too much?

I have two concerns:

  • Will some users of async libs complain about getting a second param?
  • What about if/when we switch back to using the mkdirp library, instead of our custom build?

What do you think? Is this in scope for the project? Can it be implemented without rewriting too much?

I think it's fine, although I don't see how it's much of a priority though for us unless one of us decides to do it.

Will some users of async libs complain about getting a second param?

Don't see people complaining about this since the ordering would play nice with these libraries.

What about if/when we switch back to using the mkdirp library, instead of our custom build?

As long as we have tests in place, I think it's fine.

@Loilo - if you're up for a PR, go for it. However, note the PR must include the following:

  • implementation of change for both endureDir() and ensureDirSync()
  • tests for both
  • documentation updates

@RyanZim please let me know if you disagree with any of the aforementioned.

Huh. I just realized that your implementation of those functions already does exactly that, it's even covered by the tests. It's just not stated in the documentation. 馃檲

Do you want me to attach a PR that just adds this to the docs?

@Loilo Sorry so late in getting back to you.

Do you want me to attach a PR that just adds this to the docs?

Wouldn't hurt IMO, @jprichardson?

@Loilo - yep, please do!

Attached the PR. However I have to say one should be careful about merging it in.
Now that the feature is documented, ensureFile, ensureLink and ensureSymlink would implicitely be expected to behave similarly (which they don't).

Since they are all internally using mkdir though it would be maybe worth to think about adding that behaviour.

If I find the time (not sure) I'd be happy to attach a PR this weekend.

Was this page helpful?
0 / 5 - 0 ratings