Comparing version 2.7.1 to 2.8.0
(function() { | ||
var Module, async, fs, fsPlus, isPathValid, lstatSyncNoException, mkdirp, path, rimraf, statSyncNoException, _, | ||
var Module, async, fs, fsPlus, isMoveTargetValid, isMoveTargetValidSync, isPathValid, lstatSyncNoException, mkdirp, path, rimraf, statSyncNoException, _, | ||
__slice = [].slice; | ||
@@ -229,3 +229,42 @@ | ||
}, | ||
move: function(source, target, callback) { | ||
return isMoveTargetValid(source, target, function(isMoveTargetValidErr, isTargetValid) { | ||
var error, targetParentPath; | ||
if (isMoveTargetValidErr) { | ||
callback(isMoveTargetValidErr); | ||
return; | ||
} | ||
if (!isTargetValid) { | ||
error = new Error("'" + target + "' already exists."); | ||
error.code = 'EEXIST'; | ||
callback(error); | ||
return; | ||
} | ||
targetParentPath = path.dirname(target); | ||
return fs.exists(targetParentPath, function(targetParentExists) { | ||
if (targetParentExists) { | ||
fs.rename(source, target, callback); | ||
return; | ||
} | ||
return fsPlus.makeTree(targetParentPath, function(makeTreeErr) { | ||
if (makeTreeErr) { | ||
callback(makeTreeErr); | ||
return; | ||
} | ||
return fs.rename(source, target, callback); | ||
}); | ||
}); | ||
}); | ||
}, | ||
moveSync: function(source, target) { | ||
var error, targetParentPath; | ||
if (!isMoveTargetValidSync(source, target)) { | ||
error = new Error("'" + target + "' already exists."); | ||
error.code = 'EEXIST'; | ||
throw error; | ||
} | ||
targetParentPath = path.dirname(target); | ||
if (!fs.existsSync(targetParentPath)) { | ||
fsPlus.makeTreeSync(targetParentPath); | ||
} | ||
return fs.renameSync(source, target); | ||
@@ -528,4 +567,30 @@ }, | ||
isMoveTargetValid = function(source, target, callback) { | ||
return fs.stat(source, function(oldErr, oldStat) { | ||
if (oldErr) { | ||
callback(oldErr); | ||
return; | ||
} | ||
return fs.stat(target, function(newErr, newStat) { | ||
if (newErr && newErr.code === 'ENOENT') { | ||
callback(void 0, true); | ||
return; | ||
} | ||
return callback(void 0, source.toLowerCase() === target.toLowerCase() && oldStat.dev === newStat.dev && oldStat.ino === newStat.ino); | ||
}); | ||
}); | ||
}; | ||
isMoveTargetValidSync = function(source, target) { | ||
var newStat, oldStat; | ||
oldStat = statSyncNoException(source); | ||
newStat = statSyncNoException(target); | ||
if (!(oldStat && newStat)) { | ||
return true; | ||
} | ||
return source.toLowerCase() === target.toLowerCase() && oldStat.dev === newStat.dev && oldStat.ino === newStat.ino; | ||
}; | ||
module.exports = _.extend({}, fs, fsPlus); | ||
}).call(this); |
{ | ||
"name": "fs-plus", | ||
"version": "2.7.1", | ||
"version": "2.8.0", | ||
"description": "node's fs with more helpers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/fs-plus.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28518
578