diff options
Diffstat (limited to 'node_modules/rimraf/rimraf.js')
-rw-r--r-- | node_modules/rimraf/rimraf.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/node_modules/rimraf/rimraf.js b/node_modules/rimraf/rimraf.js index 6a67fb430..6c8bf98ec 100644 --- a/node_modules/rimraf/rimraf.js +++ b/node_modules/rimraf/rimraf.js @@ -63,16 +63,20 @@ function rimraf_ (p, cb) { if (er && er.code === "ENOENT") return cb() if (er && (er.code === "EPERM" || er.code === "EISDIR")) - return rmdir(p, cb) + return rmdir(p, er, cb) return cb(er) }) } -function rmdir (p, cb) { +function rmdir (p, originalEr, cb) { // try to rmdir first, and only readdir on ENOTEMPTY + // if we guessed wrong, and it's not a directory, then + // raise the original error. fs.rmdir(p, function (er) { if (er && er.code === "ENOTEMPTY") rmkids(p, cb) + else if (er && er.code === "ENOTDIR") + cb(originalEr) else cb(er) }) @@ -110,9 +114,19 @@ function rimrafSync (p) { return if (er.code !== "EPERM" && er.code !== "EISDIR") throw er - fs.readdirSync(p).forEach(function (f) { - rimrafSync(path.join(p, f)) - }) - fs.rmdirSync(p) + try { + fs.rmdirSync(p) + } catch (er2) { + if (er2.code === "ENOENT") + return + if (er2.code === "ENOTDIR") + throw er + if (er2.code === "ENOTEMPTY") { + fs.readdirSync(p).forEach(function (f) { + rimrafSync(path.join(p, f)) + }) + fs.rmdirSync(p) + } + } } } |