-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Added recursive directory creation to the fs.mkdir() function #513
Conversation
Thanks, but it needs to match style, have tests and docs. |
Please see my latest commits and let me know what you think. |
I'm not sure, but wouldn't |
Hi thejh, I agree and I'm changing to Other than this, what do you think of my implementation? Thanks |
@@ -26,8 +28,18 @@ fs.mkdir(d, 0666, function(err) { | |||
} | |||
}); | |||
|
|||
fs.mkdir(recursive_d, 0766, true, function(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another hardcoded permission, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a test. The directory name is also hardcoded and previous tests also had the permission hardcoded.
Do you see a problem with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, didn't look at the filename.
When will this be added to the core? |
I'm not sure if/when this will be added to the core. In the meanwhile I've created an npm module called node-fs: https://github.com/bpedro/node-fs |
Thanks! |
|
It's always easier to click than to copy+paste, so here's a hyperlink: https://npmjs.org/package/mkdirp |
It's baffling why this still isn't in the core. |
IMO This is the exact point that a specified 3rd party module should provide the solution. (ie mkdirp) I don't remember a framework has this kind of functionality in the core. |
It's a very common use case and I'd argue that any framework, or library should consider common use cases as something that should be in the core. Not really worth arguing about, but this is the single reason that it baffles me. I don't believe it's a good design choice is all. |
It's important that a design decision for node was to basically provide (where sensible) a javascript interface to the common posix interfaces that are consumed. http://pubs.opengroup.org/onlinepubs/009695399/functions/mkdir.html does not define a recursive mechanism for it, and it's relatively trivial to implement in userland, so that's why node doesn't implement it. Here's roughly the balance we try and strike:
Sometimes we do well, and sometimes we don't, but that's the position we try and work from. |
Thanks for the link and kudos for a thorough explanation. It actually says to throw |
Implemented a polymorphic approach to the mkdir function making it also create directories recursively. This is the functionality offered by 'mkdir -p' and is often desirable to have it available from within node.
Here's the new mkdir() function synopsis:
This change doesn't break any existing test.
Example usage: