diff --git a/lib/wrench.js b/lib/wrench.js index b45b5d3..8a6438c 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -138,16 +138,16 @@ exports.rmdirSyncRecursive = function(path, failSilent) { /* Loop through and delete everything in the sub-tree after checking it */ 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 - exports.rmdirSyncRecursive(path + "/" + files[i]); + exports.rmdirSyncRecursive(_path.join(path, files[i])); 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? - 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 @@ -190,7 +190,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { 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) { if(typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return; @@ -201,25 +201,25 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { if(currFile.isDirectory()) { /* 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()) { - var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]); + var symlinkFull = fs.readlinkSync(_path.join(sourceDir, files[i])); if (!opts.inflateSymlinks) { - fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]); + fs.symlinkSync(symlinkFull, _path.join(newDirLocation, files[i])); continue; } - var tmpCurrFile = fs.lstatSync(sourceDir + "/" + symlinkFull); + var tmpCurrFile = fs.lstatSync(_path.join(sourceDir, symlinkFull)); if (tmpCurrFile.isDirectory()) { - exports.copyDirSyncRecursive(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i], opts); + exports.copyDirSyncRecursive(_path.join(sourceDir, symlinkFull), _path.join(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]); + fCopyFile(_path.join(sourceDir, symlinkFull), _path.join(newDirLocation, files[i])); } } else { /* 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); 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()) { /* ...and recursion this thing right on back. */ - exports.chmodSyncRecursive(sourceDir + "/" + files[i], filemode); + exports.chmodSyncRecursive(_path.join(sourceDir, files[i]), filemode); } else { /* 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); 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()) { /* ...and recursion this thing right on back. */ - exports.chownSyncRecursive(sourceDir + "/" + files[i], uid, gid); + exports.chownSyncRecursive(_path.join(sourceDir, files[i]), uid, gid); } else { /* 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 self = this; + path = _path.normalize(path) try { fs.mkdirSync(path, mode); } catch(err) { if(err.code == "ENOENT") { - var slashIdx = path.lastIndexOf("/"); - if(slashIdx < 0) { - slashIdx = path.lastIndexOf("\\"); - } + var slashIdx = path.lastIndexOf(_path.sep); if(slashIdx > 0) { var parentPath = path.substring(0, slashIdx);