diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/shelljs/src/mv.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/shelljs/src/mv.js')
-rw-r--r-- | node_modules/shelljs/src/mv.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/node_modules/shelljs/src/mv.js b/node_modules/shelljs/src/mv.js index 7fc7cf04c..6ebaa8a03 100644 --- a/node_modules/shelljs/src/mv.js +++ b/node_modules/shelljs/src/mv.js @@ -11,6 +11,14 @@ common.register('mv', _mv, { }, }); +// Checks if cureent file was created recently +function checkRecentCreated(sources, index) { + var lookedSource = sources[index]; + return sources.slice(0, index).some(function (src) { + return path.basename(src) === path.basename(lookedSource); + }); +} + //@ //@ ### mv([options ,] source [, source ...], dest') //@ ### mv([options ,] source_array, dest') @@ -55,7 +63,7 @@ function _mv(options, sources, dest) { common.error('dest file already exists: ' + dest); } - sources.forEach(function (src) { + sources.forEach(function (src, srcIndex) { if (!fs.existsSync(src)) { common.error('no such file or directory: ' + src, { continue: true }); return; // skip file @@ -70,6 +78,16 @@ function _mv(options, sources, dest) { thisDest = path.normalize(dest + '/' + path.basename(src)); } + var thisDestExists = fs.existsSync(thisDest); + + if (thisDestExists && checkRecentCreated(sources, srcIndex)) { + // cannot overwrite file created recently in current execution, but we want to continue copying other files + if (!options.no_force) { + common.error("will not overwrite just-created '" + thisDest + "' with '" + src + "'", { continue: true }); + } + return; + } + if (fs.existsSync(thisDest) && options.no_force) { common.error('dest file already exists: ' + thisDest, { continue: true }); return; // skip file |