Merge pull request +15887 from c9/vfs-improve-mkfile

do not call mkdirp unnecessarily when saving files
pull/468/merge
Harutyun Amirjanyan 2017-12-18 16:08:42 +04:00 zatwierdzone przez GitHub
commit 7de17567e2
1 zmienionych plików z 10 dodań i 9 usunięć

19
node_modules/vfs-local/localfs.js wygenerowano vendored
Wyświetl plik

@ -738,6 +738,8 @@ module.exports = function setup(fsOptions) {
var tempPath; var tempPath;
var resolvedPath = ""; var resolvedPath = "";
var mode = options.mode || 0666 & ~umask; var mode = options.mode || 0666 & ~umask;
var createParents = options.parents;
start(); start();
@ -772,15 +774,7 @@ module.exports = function setup(fsOptions) {
} }
function start() { function start() {
if (options.parents) { resolve();
mkdirP(dirname(path), options, function(err) {
if (err) return error(err);
resolve();
});
}
else {
resolve();
}
} }
// Make sure the user has access to the directory and get the real path. // 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. // 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. // In that case, just resolve the parent path and go from there.
resolvePath(dirname(path), options, function (err, dir) { 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); if (err) return error(err);
resolvedPath = join(dir, basename(path)); resolvedPath = join(dir, basename(path));
createTempFile(); createTempFile();