From ece14b664d7f8f0880a9666defad1564ab839bfa Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 30 Jun 2015 11:02:09 -0700 Subject: [PATCH] Use async function for bin The better to handle win32's EBUSY. Fix #74 --- bin.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bin.js b/bin.js index 29bfa8a6..1bd5a0d1 100755 --- a/bin.js +++ b/bin.js @@ -18,7 +18,7 @@ var args = process.argv.slice(2).filter(function(arg) { if (help || args.length === 0) { // If they didn't ask for help, then this is not a "success" var log = help ? console.log : console.error - log('Usage: rimraf ') + log('Usage: rimraf [ ...]') log('') log(' Deletes all files and folders at "path" recursively.') log('') @@ -26,8 +26,15 @@ if (help || args.length === 0) { log('') log(' -h, --help Display this usage info') process.exit(help ? 0 : 1) -} else { - args.forEach(function(arg) { - rimraf.sync(arg) +} else + go(0) + +function go (n) { + if (n >= args.length) + return + rimraf(args[n], function (er) { + if (er) + throw er + go(n+1) }) }