summaryrefslogtreecommitdiff
path: root/lib/internal/fs/promises.js
diff options
context:
space:
mode:
authorBenjamin Coe <ben@npmjs.com>2018-08-09 16:52:41 -0700
committerBenjamin Coe <ben@npmjs.com>2018-08-11 12:07:32 -0700
commitbdef1b1eb45e2953e1ff68f0cc9a68ec83573e57 (patch)
treecf12dfaaa414432980c139066aa977ffc0724760 /lib/internal/fs/promises.js
parente0395247c899af101f8a1f76a8554be1ff14040a (diff)
downloadandroid-node-v8-bdef1b1eb45e2953e1ff68f0cc9a68ec83573e57.tar.gz
android-node-v8-bdef1b1eb45e2953e1ff68f0cc9a68ec83573e57.tar.bz2
android-node-v8-bdef1b1eb45e2953e1ff68f0cc9a68ec83573e57.zip
fs: implement mkdir recursive (mkdirp)
Implements mkdirp functionality in node_file.cc. The Benefit of implementing in C++ layer is that the logic is more easily shared between the Promise and callback implementation and there are notable performance improvements. This commit is part of the Tooling Group Initiative. Refs: https://github.com/nodejs/user-feedback/pull/70 PR-URL: https://github.com/nodejs/node/pull/21875 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/internal/fs/promises.js')
-rw-r--r--lib/internal/fs/promises.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js
index f38a3e59be..e8cb2317fa 100644
--- a/lib/internal/fs/promises.js
+++ b/lib/internal/fs/promises.js
@@ -289,11 +289,23 @@ async function fsync(handle) {
return binding.fsync(handle.fd, kUsePromises);
}
-async function mkdir(path, mode) {
+async function mkdir(path, options) {
+ if (typeof options === 'number' || typeof options === 'string') {
+ options = { mode: options };
+ }
+ const {
+ recursive = false,
+ mode = 0o777
+ } = options || {};
path = getPathFromURL(path);
+
validatePath(path);
- mode = validateMode(mode, 'mode', 0o777);
- return binding.mkdir(pathModule.toNamespacedPath(path), mode, kUsePromises);
+ if (typeof recursive !== 'boolean')
+ throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', recursive);
+
+ return binding.mkdir(pathModule.toNamespacedPath(path),
+ validateMode(mode, 'mode', 0o777), recursive,
+ kUsePromises);
}
async function readdir(path, options) {