Point release, adds some stuff from pull request #55
This commit is contained in:
parent
f6074405ba
commit
0f21829511
2 changed files with 29 additions and 22 deletions
|
|
@ -14,7 +14,6 @@
|
|||
var fs = require("fs"),
|
||||
_path = require("path");
|
||||
|
||||
|
||||
/* wrench.readdirSyncRecursive("directory_path");
|
||||
*
|
||||
* Recursively dives through directories and read the contents of all the
|
||||
|
|
@ -202,6 +201,8 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
|
|||
|
||||
var contents = fs.readFileSync(srcFile);
|
||||
fs.writeFileSync(destFile, contents);
|
||||
var stat = fs.lstatSync(srcFile);
|
||||
fs.chmodSync(destFile, stat.mode);
|
||||
};
|
||||
|
||||
if(currFile.isDirectory()) {
|
||||
|
|
@ -289,29 +290,32 @@ exports.chownSyncRecursive = function(sourceDir, uid, gid) {
|
|||
* Recursively dives through directories and obliterates everything about it.
|
||||
*/
|
||||
exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
|
||||
fs.readdir(dir, function(err, files){
|
||||
if(clbk === null || typeof clbk == 'undefined')
|
||||
clbk = function(err) {};
|
||||
|
||||
fs.readdir(dir, function(err, files) {
|
||||
if(err && typeof failSilent === 'boolean' && !failSilent)
|
||||
return clbk(err);
|
||||
|
||||
if(typeof failSilent === 'function')
|
||||
clbk = failSilent;
|
||||
if(typeof failSilent === 'function')
|
||||
clbk = failSilent;
|
||||
|
||||
(function rmFile(err){
|
||||
if (err) return clbk(err);
|
||||
|
||||
var filename = files.shift();
|
||||
if (filename === null || typeof filename == 'undefined')
|
||||
return fs.rmdir(dir, clbk);
|
||||
|
||||
var file = dir+'/'+filename;
|
||||
fs.lstat(file, function(err, stat){
|
||||
(function rmFile(err){
|
||||
if (err) return clbk(err);
|
||||
if (stat.isDirectory())
|
||||
rmdirRecursive(file, rmFile);
|
||||
else
|
||||
fs.unlink(file, rmFile);
|
||||
});
|
||||
})();
|
||||
|
||||
var filename = files.shift();
|
||||
if (filename === null || typeof filename == 'undefined')
|
||||
return fs.rmdir(dir, clbk);
|
||||
|
||||
var file = dir+'/'+filename;
|
||||
fs.lstat(file, function(err, stat){
|
||||
if (err) return clbk(err);
|
||||
if (stat.isDirectory())
|
||||
rmdirRecursive(file, rmFile);
|
||||
else
|
||||
fs.unlink(file, rmFile);
|
||||
});
|
||||
})();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -324,12 +328,15 @@ exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
|
|||
*/
|
||||
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
|
||||
var originalArguments = Array.prototype.slice.apply(arguments);
|
||||
srcDir = _path.normalize(srcDir);
|
||||
newDir = _path.normalize(newDir);
|
||||
|
||||
fs.stat(newDir, function(err, newDirStat){
|
||||
if(!err) {
|
||||
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
|
||||
return exports.rmdirRecursive(newDir, function(err){
|
||||
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.'));
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue