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.
This commit is contained in:
Brandon Freitag 2016-01-05 23:15:31 -08:00 committed by Brandon Freitag
parent dc5c59be36
commit 9ce87da61b

View File

@ -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