Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Point release, adds some stuff from pull request #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan McGrath committed Oct 15, 2013
1 parent f607440 commit 0f21829
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
47 changes: 27 additions & 20 deletions lib/wrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
(function rmFile(err){
if (err) return clbk(err);

var filename = files.shift();
if (filename === null || typeof filename == 'undefined')
return fs.rmdir(dir, clbk);
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);
});
})();
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);
});
})();
});
};

Expand All @@ -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.'));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wrench",
"description": "Recursive filesystem (and other) operations that Node *should* have.",
"version": "1.5.1",
"version": "1.5.2",
"author": "Ryan McGrath <[email protected]>",

"repository": {
Expand Down

0 comments on commit 0f21829

Please sign in to comment.