Fixing some cross-platform path issues #43
2 changed files with 26 additions and 28 deletions
|
|
@ -138,16 +138,16 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
|
||||||
|
|
||||||
/* Loop through and delete everything in the sub-tree after checking it */
|
/* Loop through and delete everything in the sub-tree after checking it */
|
||||||
for(var i = 0; i < files.length; i++) {
|
for(var i = 0; i < files.length; i++) {
|
||||||
var currFile = fs.lstatSync(path + "/" + files[i]);
|
var currFile = fs.lstatSync(_path.join(path, files[i]));
|
||||||
|
|
||||||
if(currFile.isDirectory()) // Recursive function back to the beginning
|
if(currFile.isDirectory()) // Recursive function back to the beginning
|
||||||
exports.rmdirSyncRecursive(path + "/" + files[i]);
|
exports.rmdirSyncRecursive(_path.join(path, files[i]));
|
||||||
|
|
||||||
else if(currFile.isSymbolicLink()) // Unlink symlinks
|
else if(currFile.isSymbolicLink()) // Unlink symlinks
|
||||||
fs.unlinkSync(path + "/" + files[i]);
|
fs.unlinkSync(_path.join(path, files[i]));
|
||||||
|
|
||||||
else // Assume it's a file - perhaps a try/catch belongs here?
|
else // Assume it's a file - perhaps a try/catch belongs here?
|
||||||
fs.unlinkSync(path + "/" + files[i]);
|
fs.unlinkSync(_path.join(path, files[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now that we know everything in the sub-tree has been deleted, we can delete the main
|
/* Now that we know everything in the sub-tree has been deleted, we can delete the main
|
||||||
|
|
@ -190,7 +190,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
|
||||||
if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue;
|
if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
|
var currFile = fs.lstatSync(_path.join(sourceDir, files[i]));
|
||||||
|
|
||||||
var fCopyFile = function(srcFile, destFile) {
|
var fCopyFile = function(srcFile, destFile) {
|
||||||
if(typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return;
|
if(typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return;
|
||||||
|
|
@ -201,25 +201,25 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
|
||||||
|
|
||||||
if(currFile.isDirectory()) {
|
if(currFile.isDirectory()) {
|
||||||
/* recursion this thing right on back. */
|
/* recursion this thing right on back. */
|
||||||
exports.copyDirSyncRecursive(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts);
|
exports.copyDirSyncRecursive(_path.join(sourceDir, files[i]), _path.join(newDirLocation, files[i]), opts);
|
||||||
} else if(currFile.isSymbolicLink()) {
|
} else if(currFile.isSymbolicLink()) {
|
||||||
var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]);
|
var symlinkFull = fs.readlinkSync(_path.join(sourceDir, files[i]));
|
||||||
|
|
||||||
if (!opts.inflateSymlinks) {
|
if (!opts.inflateSymlinks) {
|
||||||
fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]);
|
fs.symlinkSync(symlinkFull, _path.join(newDirLocation, files[i]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmpCurrFile = fs.lstatSync(sourceDir + "/" + symlinkFull);
|
var tmpCurrFile = fs.lstatSync(_path.join(sourceDir, symlinkFull));
|
||||||
if (tmpCurrFile.isDirectory()) {
|
if (tmpCurrFile.isDirectory()) {
|
||||||
exports.copyDirSyncRecursive(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i], opts);
|
exports.copyDirSyncRecursive(_path.join(sourceDir, symlinkFull), _path.join(newDirLocation, files[i]), opts);
|
||||||
} else {
|
} else {
|
||||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||||
fCopyFile(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i]);
|
fCopyFile(_path.join(sourceDir, symlinkFull), _path.join(newDirLocation, files[i]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||||
fCopyFile(sourceDir + "/" + files[i], newDirLocation + "/" + files[i]);
|
fCopyFile(_path.join(sourceDir, files[i]), _path.join(newDirLocation, files[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -235,14 +235,14 @@ exports.chmodSyncRecursive = function(sourceDir, filemode) {
|
||||||
var files = fs.readdirSync(sourceDir);
|
var files = fs.readdirSync(sourceDir);
|
||||||
|
|
||||||
for(var i = 0; i < files.length; i++) {
|
for(var i = 0; i < files.length; i++) {
|
||||||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
|
var currFile = fs.lstatSync(_path.join(sourceDir, files[i]));
|
||||||
|
|
||||||
if(currFile.isDirectory()) {
|
if(currFile.isDirectory()) {
|
||||||
/* ...and recursion this thing right on back. */
|
/* ...and recursion this thing right on back. */
|
||||||
exports.chmodSyncRecursive(sourceDir + "/" + files[i], filemode);
|
exports.chmodSyncRecursive(_path.join(sourceDir, files[i]), filemode);
|
||||||
} else {
|
} else {
|
||||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||||
fs.chmod(sourceDir + "/" + files[i], filemode);
|
fs.chmod(_path.join(sourceDir, files[i]), filemode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,14 +262,14 @@ exports.chownSyncRecursive = function(sourceDir, uid, gid) {
|
||||||
var files = fs.readdirSync(sourceDir);
|
var files = fs.readdirSync(sourceDir);
|
||||||
|
|
||||||
for(var i = 0; i < files.length; i++) {
|
for(var i = 0; i < files.length; i++) {
|
||||||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
|
var currFile = fs.lstatSync(_path.join(sourceDir, files[i]));
|
||||||
|
|
||||||
if(currFile.isDirectory()) {
|
if(currFile.isDirectory()) {
|
||||||
/* ...and recursion this thing right on back. */
|
/* ...and recursion this thing right on back. */
|
||||||
exports.chownSyncRecursive(sourceDir + "/" + files[i], uid, gid);
|
exports.chownSyncRecursive(_path.join(sourceDir, files[i]), uid, gid);
|
||||||
} else {
|
} else {
|
||||||
/* At this point, we've hit a file actually worth chowning... so own it. */
|
/* At this point, we've hit a file actually worth chowning... so own it. */
|
||||||
fs.chownSync(sourceDir + "/" + files[i], uid, gid);
|
fs.chownSync(_path.join(sourceDir, files[i]), uid, gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,15 +355,13 @@ exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, clbk) {
|
||||||
|
|
||||||
var mkdirSyncRecursive = function(path, mode) {
|
var mkdirSyncRecursive = function(path, mode) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
path = _path.normalize(path)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(path, mode);
|
fs.mkdirSync(path, mode);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if(err.code == "ENOENT") {
|
if(err.code == "ENOENT") {
|
||||||
var slashIdx = path.lastIndexOf("/");
|
var slashIdx = path.lastIndexOf(_path.sep);
|
||||||
if(slashIdx < 0) {
|
|
||||||
slashIdx = path.lastIndexOf("\\");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(slashIdx > 0) {
|
if(slashIdx > 0) {
|
||||||
var parentPath = path.substring(0, slashIdx);
|
var parentPath = path.substring(0, slashIdx);
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ module.exports = testCase({
|
||||||
var dir = path.join(__dirname, 'shown');
|
var dir = path.join(__dirname, 'shown');
|
||||||
var testdir = path.join(__dirname, 'testdir');
|
var testdir = path.join(__dirname, 'testdir');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false });
|
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false });
|
||||||
|
|
@ -107,7 +107,7 @@ module.exports = testCase({
|
||||||
var dir = path.join(__dirname, 'shown');
|
var dir = path.join(__dirname, 'shown');
|
||||||
var testdir = path.join(__dirname, 'testdir');
|
var testdir = path.join(__dirname, 'testdir');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: true });
|
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: true });
|
||||||
|
|
@ -124,7 +124,7 @@ module.exports = testCase({
|
||||||
var dir = path.join(__dirname, 'withsymlinks');
|
var dir = path.join(__dirname, 'withsymlinks');
|
||||||
var testdir = path.join(__dirname, 'testdir');
|
var testdir = path.join(__dirname, 'testdir');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: true });
|
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: true });
|
||||||
|
|
@ -141,7 +141,7 @@ module.exports = testCase({
|
||||||
var dir = path.join(__dirname, 'withsymlinks');
|
var dir = path.join(__dirname, 'withsymlinks');
|
||||||
var testdir = path.join(__dirname, 'testdir');
|
var testdir = path.join(__dirname, 'testdir');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: false });
|
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: false });
|
||||||
|
|
@ -159,7 +159,7 @@ module.exports = testCase({
|
||||||
testdir1 = path.join(__dirname, 'testdir1'),
|
testdir1 = path.join(__dirname, 'testdir1'),
|
||||||
testdir2 = path.join(__dirname, 'testdir2');
|
testdir2 = path.join(__dirname, 'testdir2');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir1, 0777);
|
wrench.mkdirSyncRecursive(testdir1, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false });
|
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false });
|
||||||
|
|
@ -184,7 +184,7 @@ module.exports = testCase({
|
||||||
testdir1 = path.join(__dirname, 'testdir1'),
|
testdir1 = path.join(__dirname, 'testdir1'),
|
||||||
testdir2 = path.join(__dirname, 'testdir2');
|
testdir2 = path.join(__dirname, 'testdir2');
|
||||||
|
|
||||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
test.ok(fs.existsSync(dir), 'Folders should exist');
|
||||||
|
|
||||||
wrench.mkdirSyncRecursive(testdir1, 0777);
|
wrench.mkdirSyncRecursive(testdir1, 0777);
|
||||||
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false });
|
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false });
|
||||||
|
|
|
||||||
Reference in a new issue