From 9ce87da61bab68d5489b459f5e7cbb205846db3e Mon Sep 17 00:00:00 2001 From: Brandon Freitag Date: Tue, 5 Jan 2016 23:15:31 -0800 Subject: [PATCH] Fix cp to match unix behavior In unix, if src is a directory and dest doesn't exist, 'cp -r src dest' will copy src/* into dest. Fix cp('-r', 'src', 'dest') to behave the same way. --- src/cp.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cp.js b/src/cp.js index ef19f96..b33992e 100644 --- a/src/cp.js +++ b/src/cp.js @@ -140,8 +140,12 @@ function _cp(options, sources, dest) { // Recursive allows the shortcut syntax "sourcedir/" for "sourcedir/*" // (see Github issue #15) sources.forEach(function(src, i) { - if (src[src.length - 1] === '/') + if (src[src.length - 1] === '/') { sources[i] += '*'; + // If src is a directory and dest doesn't exist, 'cp -r src dest' should copy src/* into dest + } else if (fs.statSync(src).isDirectory() && !exists) { + sources[i] += '/*'; + } }); // Create dest