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"),
|
var fs = require("fs"),
|
||||||
_path = require("path");
|
_path = require("path");
|
||||||
|
|
||||||
|
|
||||||
/* wrench.readdirSyncRecursive("directory_path");
|
/* wrench.readdirSyncRecursive("directory_path");
|
||||||
*
|
*
|
||||||
* Recursively dives through directories and read the contents of all the
|
* 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);
|
var contents = fs.readFileSync(srcFile);
|
||||||
fs.writeFileSync(destFile, contents);
|
fs.writeFileSync(destFile, contents);
|
||||||
|
var stat = fs.lstatSync(srcFile);
|
||||||
|
fs.chmodSync(destFile, stat.mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
if(currFile.isDirectory()) {
|
if(currFile.isDirectory()) {
|
||||||
|
|
@ -289,29 +290,32 @@ exports.chownSyncRecursive = function(sourceDir, uid, gid) {
|
||||||
* Recursively dives through directories and obliterates everything about it.
|
* Recursively dives through directories and obliterates everything about it.
|
||||||
*/
|
*/
|
||||||
exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
|
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)
|
if(err && typeof failSilent === 'boolean' && !failSilent)
|
||||||
return clbk(err);
|
return clbk(err);
|
||||||
|
|
||||||
if(typeof failSilent === 'function')
|
if(typeof failSilent === 'function')
|
||||||
clbk = failSilent;
|
clbk = failSilent;
|
||||||
|
|
||||||
(function rmFile(err){
|
(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){
|
|
||||||
if (err) return clbk(err);
|
if (err) return clbk(err);
|
||||||
if (stat.isDirectory())
|
|
||||||
rmdirRecursive(file, rmFile);
|
var filename = files.shift();
|
||||||
else
|
if (filename === null || typeof filename == 'undefined')
|
||||||
fs.unlink(file, rmFile);
|
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) {
|
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
|
||||||
var originalArguments = Array.prototype.slice.apply(arguments);
|
var originalArguments = Array.prototype.slice.apply(arguments);
|
||||||
|
srcDir = _path.normalize(srcDir);
|
||||||
|
newDir = _path.normalize(newDir);
|
||||||
|
|
||||||
fs.stat(newDir, function(err, newDirStat){
|
fs.stat(newDir, function(err, newDirStat){
|
||||||
if(!err) {
|
if(!err) {
|
||||||
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
|
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);
|
copyDirRecursive.apply(this, originalArguments);
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
|
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "wrench",
|
"name": "wrench",
|
||||||
"description": "Recursive filesystem (and other) operations that Node *should* have.",
|
"description": "Recursive filesystem (and other) operations that Node *should* have.",
|
||||||
"version": "1.5.1",
|
"version": "1.5.2",
|
||||||
"author": "Ryan McGrath <ryan@venodesigns.net>",
|
"author": "Ryan McGrath <ryan@venodesigns.net>",
|
||||||
|
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
Reference in a new issue