Updated recursive copy logic to honor the preserveFiles option

This commit is contained in:
derekslife 2015-02-21 15:54:53 -08:00
parent 13f486d867
commit 156eaceed6
2 changed files with 23 additions and 11 deletions

View file

@ -233,9 +233,9 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
try {
if(fs.statSync(newDirLocation).isDirectory()) {
if(opts.forceDelete) {
exports.rmdirSyncRecursive(newDirLocation);
} else {
return new Error('You are trying to delete a directory that already exists. Specify forceDelete in the opts argument to override this. Bailing~');
exports.rmdirSyncRecursive(newDirLocation);
} else if(!opts.preserveFiles) {
return new Error('You are trying to copy a directory onto a directory that already exists. Specify forceDelete or preserveFiles in the opts argument to specify desired behavior');
}
}
} catch(e) { }
@ -413,8 +413,9 @@ exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk)
return exports.rmdirRecursive(newDir, function(err) {
copyDirRecursive.apply(this, originalArguments);
});
else
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
else if(typeof opts !== 'undefined' && typeof opts !== 'function' && !opts.preserveFiles) {
return clbk(new Error('You are trying to copy a directory onto a directory that already exists. Specify forceDelete or preserveFiles in the opts argument to specify desired behavior'));
}
}
if(typeof opts === 'function')