added preserveFiles and inflateSymlinks options and tests
This commit is contained in:
parent
658589c35e
commit
0b54b60a53
7 changed files with 156 additions and 4 deletions
|
|
@ -151,7 +151,7 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
|
|||
}
|
||||
|
||||
/* Now that we know everything in the sub-tree has been deleted, we can delete the main
|
||||
directory. Huzzah for the shopkeep. */
|
||||
directory. Huzzah for the shopkeep. */
|
||||
return fs.rmdirSync(path);
|
||||
};
|
||||
|
||||
|
|
@ -187,16 +187,34 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
|
|||
|
||||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
|
||||
|
||||
var fCopyFile = function(srcFile, destFile) {
|
||||
if (opts.preserveFiles && fs.existsSync(destFile)) return;
|
||||
|
||||
var contents = fs.readFileSync(srcFile);
|
||||
fs.writeFileSync(destFile, contents);
|
||||
};
|
||||
|
||||
if(currFile.isDirectory()) {
|
||||
/* recursion this thing right on back. */
|
||||
exports.copyDirSyncRecursive(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts);
|
||||
} else if(currFile.isSymbolicLink()) {
|
||||
var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]);
|
||||
fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]);
|
||||
|
||||
if (!opts.inflateSymlinks) {
|
||||
fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
var tmpCurrFile = fs.lstatSync(sourceDir + "/" + symlinkFull);
|
||||
if (tmpCurrFile.isDirectory()) {
|
||||
exports.copyDirSyncRecursive(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i], opts);
|
||||
} else {
|
||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||
fCopyFile(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i]);
|
||||
}
|
||||
} else {
|
||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||
var contents = fs.readFileSync(sourceDir + "/" + files[i]);
|
||||
fs.writeFileSync(newDirLocation + "/" + files[i], contents);
|
||||
fCopyFile(sourceDir + "/" + files[i], newDirLocation + "/" + files[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Reference in a new issue