Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
add recursive option to rmdir. fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fjakobs committed May 10, 2012
1 parent e3b3774 commit 125da17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ There are no `options` for this function.

Remove a directory

There are no `options` for this function.
`options` can include:

- options.recursive - (optional, default is `false`) whether to delete everything within this directory.

`meta` in the response is empty.

Expand Down
20 changes: 18 additions & 2 deletions local/localfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,24 @@ module.exports = function setup(fsOptions) {
}

function rmdir(path, options, callback) {
// TODO: add recursive delete to options?
remove(path, fs.rmdir, callback);
if (options.recursive) {
remove(path, function(path, callback) {
var rm = spawn("rm", ["-rf", path]);
var err = "";
rm.on("stderr", function(data) {
err += data;
});
rm.on("exit", function(code) {
if (code) {
return callback("error removing directory: " + code + " " + err.join(""));
}
callback();
});
}, callback);
}
else {
remove(path, fs.rmdir, callback);
}
}

function rmfile(path, options, callback) {
Expand Down

0 comments on commit 125da17

Please sign in to comment.