diff options
Diffstat (limited to 'node_modules/rimraf')
-rw-r--r-- | node_modules/rimraf/package.json | 14 | ||||
-rw-r--r-- | node_modules/rimraf/rimraf.js | 90 |
2 files changed, 80 insertions, 24 deletions
diff --git a/node_modules/rimraf/package.json b/node_modules/rimraf/package.json index e65f9a263..ba73163ba 100644 --- a/node_modules/rimraf/package.json +++ b/node_modules/rimraf/package.json @@ -1,6 +1,6 @@ { "name": "rimraf", - "version": "2.2.0", + "version": "2.2.2", "main": "rimraf.js", "description": "A deep deletion module for node (like `rm -rf`)", "author": { @@ -13,7 +13,7 @@ "url": "https://github.com/isaacs/rimraf/raw/master/LICENSE" }, "optionalDependencies": { - "graceful-fs": "~1" + "graceful-fs": "~2" }, "repository": { "type": "git", @@ -54,8 +54,12 @@ "url": "https://github.com/isaacs/rimraf/issues" }, "dependencies": { - "graceful-fs": "~1" + "graceful-fs": "~2" }, - "_id": "rimraf@2.2.0", - "_from": "rimraf@2.2" + "_id": "rimraf@2.2.2", + "dist": { + "shasum": "d99ec41dc646e55bf7a7a44a255c28bef33a8abf" + }, + "_from": "rimraf@2.2.2", + "_resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.2.tgz" } diff --git a/node_modules/rimraf/rimraf.js b/node_modules/rimraf/rimraf.js index ed915f982..55f8d9a48 100644 --- a/node_modules/rimraf/rimraf.js +++ b/node_modules/rimraf/rimraf.js @@ -16,6 +16,8 @@ var timeout = 0 exports.EMFILE_MAX = 1000 exports.BUSYTRIES_MAX = 3 +var isWindows = (process.platform === "win32") + function rimraf (p, cb) { if (!cb) throw new Error("No callback passed to rimraf()") @@ -60,14 +62,55 @@ function rimraf (p, cb) { // be made configurable somehow. But until then, YAGNI. function rimraf_ (p, cb) { fs.unlink(p, function (er) { - if (er && er.code === "ENOENT") - return cb() - if (er && (er.code === "EPERM" || er.code === "EISDIR")) - return rmdir(p, er, cb) + if (er) { + if (er.code === "ENOENT") + return cb() + if (er.code === "EPERM") + return (isWindows) ? fixWinEPERM(p, er, cb) : rmdir(p, er, cb) + if (er.code === "EISDIR") + return rmdir(p, er, cb) + } return cb(er) }) } +function fixWinEPERM (p, er, cb) { + fs.chmod(p, 666, function (er2) { + if (er2) + cb(er2.code === "ENOENT" ? null : er) + else + fs.stat(p, function(er3, stats) { + if (er3) + cb(er3.code === "ENOENT" ? null : er) + else if (stats.isDirectory()) + rmdir(p, er, cb) + else + fs.unlink(p, cb) + }) + }) +} + +function fixWinEPERMSync (p, er, cb) { + try { + fs.chmodSync(p, 666) + } catch (er2) { + if (er2.code !== "ENOENT") + throw er + } + + try { + var stats = fs.statSync(p) + } catch (er3) { + if (er3 !== "ENOENT") + throw er + } + + if (stats.isDirectory()) + rmdirSync(p, er) + else + fs.unlinkSync(p) +} + function rmdir (p, originalEr, cb) { // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS) // if we guessed wrong, and it's not a directory, then @@ -112,21 +155,30 @@ function rimrafSync (p) { } catch (er) { if (er.code === "ENOENT") return - if (er.code !== "EPERM" && er.code !== "EISDIR") + if (er.code === "EPERM") + return isWindows ? fixWinEPERMSync(p, er) : rmdirSync(p, er) + if (er.code !== "EISDIR") throw er - 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) - } - } + rmdirSync(p, er) } } + +function rmdirSync (p, originalEr) { + try { + fs.rmdirSync(p) + } catch (er) { + if (er.code === "ENOENT") + return + if (er.code === "ENOTDIR") + throw originalEr + if (er.code === "ENOTEMPTY" || er.code === "EEXIST") + rmkidsSync(p) + } +} + +function rmkidsSync (p) { + fs.readdirSync(p).forEach(function (f) { + rimrafSync(path.join(p, f)) + }) + fs.rmdirSync(p) +} |