Permalink
Browse files

Try rmdir before readdir

Only readdir and remove children on ENOTEMPTY
  • Loading branch information...
1 parent 55fb0b6 commit a02488419cc859713b4e09d9f3f2b450062a10f3 @isaacs committed Jan 22, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 rimraf.js
View
@@ -69,6 +69,16 @@ function rimraf_ (p, cb) {
}
function rmdir (p, cb) {
+ // try to rmdir first, and only readdir on ENOTEMPTY
+ fs.rmdir(p, function (er) {
+ if (er && er.code === "ENOTEMPTY")
+ rmkids(p, cb)
+ else
+ cb(er)
+ })
+}
+
+function rmkids(p, cb) {
fs.readdir(p, function (er, files) {
if (er)
return cb(er)

0 comments on commit a024884

Please sign in to comment.