From 7c970fb31b34b73af3f2e3809e0d623e30ea7dbb Mon Sep 17 00:00:00 2001 From: Max Goldman Date: Thu, 21 May 2015 17:34:36 -0400 Subject: [PATCH 1/2] Add missing return Fixes #71. --- lib/ncp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ncp.js b/lib/ncp.js index 96eed47..a764c4f 100644 --- a/lib/ncp.js +++ b/lib/ncp.js @@ -91,7 +91,7 @@ function ncp (source, dest, options, callback) { return copyFile(file, target); } if(clobber) { - rmFile(target, function () { + return rmFile(target, function () { copyFile(file, target); }); } From 3c88d8a3f30b27876ac7c29881be5b1bde47e09c Mon Sep 17 00:00:00 2001 From: Max Goldman Date: Thu, 21 May 2015 17:37:18 -0400 Subject: [PATCH 2/2] Add test for too-early callback when existing files are clobbered See #71 and related issues. --- test/ncp.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/ncp.js b/test/ncp.js index ffe1244..acf7570 100644 --- a/test/ncp.js +++ b/test/ncp.js @@ -65,6 +65,26 @@ describe('ncp', function () { }); }); + describe('when using clobber=true', function () { + before(function () { + this.originalCreateReadStream = fs.createReadStream; + }); + + after(function () { + fs.createReadStream = this.originalCreateReadStream; + }); + + it('the copy is complete after callback', function (cb) { + ncp(src, out, {clobber: true}, function(err) { + fs.createReadStream = function() { + cb(new Error('createReadStream after callback')); + }; + assert.ifError(err); + process.nextTick(cb); + }); + }); + }); + describe('when using clobber=false', function () { it('the copy is completed successfully', function (cb) { ncp(src, out, function() {