Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-01-30 06:23:56 +0400
committerisaacs <i@izs.me>2012-01-30 06:23:56 +0400
commit79b7fdc69aafc0e0a5fb8bda2283c050637273b3 (patch)
tree7384bd18cfb2e6aa484f44279aa0131c3147c0ac /node_modules/rimraf/rimraf.js
parent6c6458def7beccb41b02c0c8a618f140512be4a5 (diff)
Update rimraf to 2.0.0
Diffstat (limited to 'node_modules/rimraf/rimraf.js')
-rw-r--r--node_modules/rimraf/rimraf.js90
1 files changed, 57 insertions, 33 deletions
diff --git a/node_modules/rimraf/rimraf.js b/node_modules/rimraf/rimraf.js
index e8104e9e4..df60c2913 100644
--- a/node_modules/rimraf/rimraf.js
+++ b/node_modules/rimraf/rimraf.js
@@ -16,34 +16,30 @@ var lstat = process.platform === "win32" ? "stat" : "lstat"
// for EMFILE handling
var timeout = 0
- , EMFILE_MAX = 1000
+exports.EMFILE_MAX = 1000
+exports.BUSYTRIES_MAX = 3
-function rimraf (p, opts, cb) {
- if (typeof opts === "function") cb = opts, opts = {}
+function rimraf (p, cb) {
if (!cb) throw new Error("No callback passed to rimraf()")
- if (!opts) opts = {}
var busyTries = 0
- opts.maxBusyTries = opts.maxBusyTries || 3
- if (opts.gently) opts.gently = path.resolve(opts.gently)
-
- rimraf_(p, opts, function CB (er) {
+ rimraf_(p, function CB (er) {
if (er) {
- if (er.code === "EBUSY" && busyTries < opts.maxBusyTries) {
- var time = (opts.maxBusyTries - busyTries) * 100
+ if (er.code === "EBUSY" && busyTries < exports.BUSYTRIES_MAX) {
+ var time = (exports.BUSYTRIES_MAX - busyTries) * 100
busyTries ++
// try again, with the same exact callback as this one.
return setTimeout(function () {
- rimraf_(p, opts, CB)
+ rimraf_(p, CB)
})
}
// this one won't happen if graceful-fs is used.
- if (er.code === "EMFILE" && timeout < EMFILE_MAX) {
+ if (er.code === "EMFILE" && timeout < exports.EMFILE_MAX) {
return setTimeout(function () {
- rimraf_(p, opts, CB)
+ rimraf_(p, CB)
}, timeout ++)
}
@@ -56,9 +52,8 @@ function rimraf (p, opts, cb) {
})
}
-function rimraf_ (p, opts, cb) {
+function rimraf_ (p, cb) {
fs[lstat](p, function (er, s) {
- // if the stat fails, then assume it's already gone.
if (er) {
// already gone
if (er.code === "ENOENT") return cb()
@@ -66,20 +61,55 @@ function rimraf_ (p, opts, cb) {
return cb(er)
}
- // don't delete that don't point actually live in the "gently" path
- if (opts.gently) return clobberTest(p, s, opts, cb)
- return rm_(p, s, opts, cb)
+ return rm_(p, s, false, cb)
})
}
-function rm_ (p, s, opts, cb) {
- if (!s.isDirectory()) return fs.unlink(p, cb)
+
+var myGid = function myGid () {
+ var g = process.getuid && process.getgid()
+ myGid = function myGid () { return g }
+ return g
+}
+
+var myUid = function myUid () {
+ var u = process.getuid && process.getuid()
+ myUid = function myUid () { return u }
+ return u
+}
+
+
+function writable (s) {
+ var mode = s.mode && 0777
+ , uid = myUid()
+ , gid = myGid()
+ return (mode & 0002)
+ || (gid === s.gid && (mode & 0020))
+ || (uid === s.uid && (mode & 0200))
+}
+
+function rm_ (p, s, didWritableCheck, cb) {
+ if (!didWritableCheck && !writable(s)) {
+ // make file writable
+ // user/group/world, doesn't matter at this point
+ // since it's about to get nuked.
+ return fs.chmod(p, s.mode | 0222, function (er) {
+ if (er) return cb(er)
+ rm_(p, s, true, cb)
+ })
+ }
+
+ if (!s.isDirectory()) {
+ return fs.unlink(p, cb)
+ }
+
+ // directory
fs.readdir(p, function (er, files) {
if (er) return cb(er)
asyncForEach(files.map(function (f) {
return path.join(p, f)
}), function (file, cb) {
- rimraf(file, opts, cb)
+ rimraf(file, cb)
}, function (er) {
if (er) return cb(er)
fs.rmdir(p, cb)
@@ -87,18 +117,6 @@ function rm_ (p, s, opts, cb) {
})
}
-function clobberTest (p, s, opts, cb) {
- var gently = opts.gently
- if (!s.isSymbolicLink()) next(null, path.resolve(p))
- else realish(p, next)
-
- function next (er, rp) {
- if (er) return rm_(p, s, cb)
- if (rp.indexOf(gently) !== 0) return clobberFail(p, gently, cb)
- else return rm_(p, s, opts, cb)
- }
-}
-
function realish (p, cb) {
fs.readlink(p, function (er, r) {
if (er) return cb(er)
@@ -137,7 +155,13 @@ function rimrafSync (p) {
if (er.code === "ENOENT") return
throw er
}
+
+ if (!writable(s)) {
+ fs.chmodSync(p, s.mode | 0222)
+ }
+
if (!s.isDirectory()) return fs.unlinkSync(p)
+
fs.readdirSync(p).forEach(function (f) {
rimrafSync(path.join(p, f))
})