From 0015ea705a53590e01170eb9e3ee5c445d20c2c3 Mon Sep 17 00:00:00 2001 From: Timo Tuominen Date: Wed, 31 Aug 2016 12:56:13 +0300 Subject: [PATCH 1/2] Correctly interpret options.clobber. --no-clobber results in options.clobber being false. Fixes #97. --- src/commands/cp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/cp.js b/src/commands/cp.js index 8f7f3a4..c788501 100755 --- a/src/commands/cp.js +++ b/src/commands/cp.js @@ -19,7 +19,7 @@ const cp = { args = (Array.isArray(args)) ? args : args.split(' '); args = args.filter(arg => String(arg).trim() !== ''); - options.noclobber = (options.force === true) ? false : options.noclobber; + options.noclobber = (options.force === true) ? false : !options.clobber; options.recursive = (options.R === true) ? true : options.recursive; if (args.length < 1) { From 89d5a858fb6ea0081097276f8e3227ef18c0e8d4 Mon Sep 17 00:00:00 2001 From: Timo Tuominen Date: Fri, 2 Sep 2016 11:07:18 +0300 Subject: [PATCH 2/2] Fix clobber behavior. --- dist/commands/cp.js | 10 +++++----- packages/cp/dist/commands/cp.js | 10 +++++----- src/commands/cp.js | 2 +- test/cp.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/commands/cp.js b/dist/commands/cp.js index 1a52005..8b1b17a 100755 --- a/dist/commands/cp.js +++ b/dist/commands/cp.js @@ -20,7 +20,7 @@ var cp = { return String(arg).trim() !== ''; }); - options.noclobber = options.force === true ? false : options.noclobber; + options.noclobber = options.force === true ? false : options.clobber === false; options.recursive = options.R === true ? true : options.recursive; if (args.length < 1) { @@ -140,10 +140,10 @@ function cpdirSyncRecursive(sourceDir, destDir, options) { fs.symlinkSync(symlinkFull, destFile, os.platform() === 'win32' ? 'junction' : null); // At this point, we've hit a file actually worth copying... so copy it on over. } else if (fs.existsSync(destFile) && options.noclobber) { - // be silent - } else { - copyFileSync.call(self, srcFile, destFile); - } + // be silent + } else { + copyFileSync.call(self, srcFile, destFile); + } } } diff --git a/packages/cp/dist/commands/cp.js b/packages/cp/dist/commands/cp.js index 1a52005..8b1b17a 100755 --- a/packages/cp/dist/commands/cp.js +++ b/packages/cp/dist/commands/cp.js @@ -20,7 +20,7 @@ var cp = { return String(arg).trim() !== ''; }); - options.noclobber = options.force === true ? false : options.noclobber; + options.noclobber = options.force === true ? false : options.clobber === false; options.recursive = options.R === true ? true : options.recursive; if (args.length < 1) { @@ -140,10 +140,10 @@ function cpdirSyncRecursive(sourceDir, destDir, options) { fs.symlinkSync(symlinkFull, destFile, os.platform() === 'win32' ? 'junction' : null); // At this point, we've hit a file actually worth copying... so copy it on over. } else if (fs.existsSync(destFile) && options.noclobber) { - // be silent - } else { - copyFileSync.call(self, srcFile, destFile); - } + // be silent + } else { + copyFileSync.call(self, srcFile, destFile); + } } } diff --git a/src/commands/cp.js b/src/commands/cp.js index c788501..ef6bc87 100755 --- a/src/commands/cp.js +++ b/src/commands/cp.js @@ -19,7 +19,7 @@ const cp = { args = (Array.isArray(args)) ? args : args.split(' '); args = args.filter(arg => String(arg).trim() !== ''); - options.noclobber = (options.force === true) ? false : !options.clobber; + options.noclobber = (options.force === true) ? false : (options.clobber === false); options.recursive = (options.R === true) ? true : options.recursive; if (args.length < 1) { diff --git a/test/cp.js b/test/cp.js index 02f4c3f..225cb33 100755 --- a/test/cp.js +++ b/test/cp.js @@ -101,7 +101,7 @@ describe('cp', function () { it('should not clobber existing files', function () { new $.ShellString('foxes').to('cp-d'); new $.ShellString('elephants').to('cp-e'); - cash.cp('cp-d cp-e', {noclobber: true}).should.equal(''); + cash.cp('cp-d cp-e', {clobber: false}).should.equal(''); $.test('-e', 'cp-d').should.equal(true); $.cat('cp-d').should.equal('foxes'); $.cat('cp-e').should.equal('elephants');