From c21026c3fb76e90835b451212fe53235c4d950da Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 10 Dec 2017 00:57:34 +0400 Subject: [PATCH] do not call mkdirp unnecessarily when saving files --- node_modules/vfs-local/localfs.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/node_modules/vfs-local/localfs.js b/node_modules/vfs-local/localfs.js index 03b91601..5a7e1ae9 100644 --- a/node_modules/vfs-local/localfs.js +++ b/node_modules/vfs-local/localfs.js @@ -738,6 +738,8 @@ module.exports = function setup(fsOptions) { var tempPath; var resolvedPath = ""; var mode = options.mode || 0666 & ~umask; + + var createParents = options.parents; start(); @@ -772,15 +774,7 @@ module.exports = function setup(fsOptions) { } function start() { - if (options.parents) { - mkdirP(dirname(path), options, function(err) { - if (err) return error(err); - resolve(); - }); - } - else { - resolve(); - } + resolve(); } // Make sure the user has access to the directory and get the real path. @@ -794,6 +788,13 @@ module.exports = function setup(fsOptions) { // If checkSymlinks is on we'll get an ENOENT when creating a new file. // In that case, just resolve the parent path and go from there. resolvePath(dirname(path), options, function (err, dir) { + if (err && err.code === "ENOENT" && createParents) { + createParents = false; + return mkdirP(dirname(path), options, function(err) { + if (err) return error(err); + resolve(); + }); + } if (err) return error(err); resolvedPath = join(dir, basename(path)); createTempFile();