From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/shelljs/src/mv.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'node_modules/shelljs/src/mv.js') 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 -- cgit v1.2.3