Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions lib/rmdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Remove all files in the given path recursively.
*/
var fs = require('fs');
var Flow = require('node.flow');

function rmdir(dir, options, callback) {
if (typeof options === 'undefined') {
Expand Down Expand Up @@ -56,32 +55,30 @@ function rmdir(dir, options, callback) {

xfs.lstat(file, function (err, stat) {
function rm_all_dirs(callback) {
var flow = new Flow();

if (!--pending) {
if (!_dirs.length) return callback();

_dirs.forEach(function (dir) {
flow.parallel(function (ready) {
var promises = _dirs.map(function (dir) {
return new Promise(function (resolve, reject) {
xfs.exists(dir, function (exists) {
if (!exists) return ready();
if (!exists) return resolve();

xfs.rmdir(dir, function (err) {
if (err) return ready(err);
if (err) return reject(err);

ready();
resolve();
});
});
});
});

flow.join().
error(function (err) {
if (err) callback(err, _dirs, _files);
}).
end(function () {
callback(null, _dirs, _files);
});
Promise.all(promises)
.then(function () {
callback(null, _dirs, _files);
})
.catch(function (err) {
if (err) callback(err, _dirs, _files);
});
}
}

Expand Down
59 changes: 36 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
{
"name" : "rmdir",
"version" : "1.2.0",
"name": "rmdir",
"version": "1.2.0",
"description": "Remove all files in the given path recursively",
"keywords" : [
"remove", "remove files", "remove all files", "remove path",
"remove dir", "rm -r", "rmdir", "remove files recursively"
"keywords": [
"remove",
"remove files",
"remove all files",
"remove path",
"remove dir",
"rm -r",
"rmdir",
"remove files recursively"
],
"author" : "dreamerslab <ben@dreamerslab.com>",
"author": "dreamerslab <ben@dreamerslab.com>",
"contributors": [
{ "name": "Aaron Larner" },
{ "name": "Glen R. Goodwin" },
{
"name" : "David Pate",
"name": "Aaron Larner"
},
{
"name": "Glen R. Goodwin"
},
{
"name": "David Pate",
"email": "davidtpate@gmail.com",
"url" : "http://davidtpate.com"
"url": "http://davidtpate.com"
},
{
"name" : "Radare",
"name": "Radare",
"email": "pancake@nopcode.org",
"url" : "http://www.radare.org/"
"url": "http://www.radare.org/"
}
],
"dependencies": {
"node.flow" : "1.2.3"
},
"repository" : {
"repository": {
"type": "git",
"url" : "https://github.com/dreamerslab/node.rmdir.git"
"url": "https://github.com/dreamerslab/node.rmdir.git"
},
"main" : "index",
"engines" : [ "node >= 0.8.0" ],
"licenses": [{
"type": "MIT",
"url" : "http://en.wikipedia.org/wiki/MIT_License"
}],
"scripts" : {
"test" : "node test/run.js"
"main": "index",
"engines": [
"node >= 0.8.0"
],
"licenses": [
{
"type": "MIT",
"url": "http://en.wikipedia.org/wiki/MIT_License"
}
],
"scripts": {
"test": "node test/run.js"
}
}