$tw.utils.copyDirectory: Ensure directories don't overlap

optimising-macrocalls
jeremy@jermolene.com 2020-04-27 15:00:06 +01:00
rodzic ad575efdcc
commit 13b8281f6b
1 zmienionych plików z 6 dodań i 2 usunięć

Wyświetl plik

@ -36,8 +36,12 @@ Recursively (and synchronously) copy a directory and all its content
*/
exports.copyDirectory = function(srcPath,dstPath) {
// Remove any trailing path separators
srcPath = $tw.utils.removeTrailingSeparator(srcPath);
dstPath = $tw.utils.removeTrailingSeparator(dstPath);
srcPath = path.resolve($tw.utils.removeTrailingSeparator(srcPath));
dstPath = path.resolve($tw.utils.removeTrailingSeparator(dstPath));
// Check that neither director is within the other
if(srcPath.substring(0,dstPath.length) === dstPath || dstPath.substring(0,srcPath.length) === srcPath) {
return "Cannot copy nested directories";
}
// Create the destination directory
var err = $tw.utils.createDirectory(dstPath);
if(err) {