Comparing version 1.0.9 to 2.0.0
{"name":"rimraf" | ||
,"version":"1.0.9" | ||
,"version":"2.0.0" | ||
,"main":"rimraf.js" | ||
@@ -8,3 +8,4 @@ ,"description":"A deep deletion module for node (like `rm -rf`)" | ||
{"type":"MIT", "url": "https://github.com/isaacs/rimraf/raw/master/LICENSE"} | ||
,"optionalDependencies":{"graceful-fs":"~1.1"} | ||
,"repository":"git://github.com/isaacs/rimraf.git" | ||
,"scripts":{"test":"cd test && bash run.sh"}} |
@@ -7,3 +7,3 @@ A `rm -rf` for node. | ||
`rimraf(f, [options,] callback)` | ||
`rimraf(f, callback)` | ||
@@ -18,14 +18,3 @@ The callback will be called with an error if there is one. Certain | ||
## Options | ||
The options object is optional. These fields are respected: | ||
* `maxBusyTries` - The number of times to retry a file or folder in the | ||
event of an `EBUSY` error. The default is 3. | ||
* `gently` - If provided a `gently` path, then rimraf will only delete | ||
files and folders that are beneath this path, and only delete symbolic | ||
links that point to a place within this path. (This is very important | ||
to npm's use-case, and shows rimraf's pedigree.) | ||
## rimraf.sync | ||
@@ -32,0 +21,0 @@ |
@@ -19,23 +19,19 @@ module.exports = rimraf | ||
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) | ||
}) | ||
@@ -45,5 +41,5 @@ } | ||
// 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 ++) | ||
@@ -61,5 +57,4 @@ } | ||
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) { | ||
@@ -72,10 +67,45 @@ // already gone | ||
// 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) { | ||
@@ -86,3 +116,3 @@ if (er) return cb(er) | ||
}), function (file, cb) { | ||
rimraf(file, opts, cb) | ||
rimraf(file, cb) | ||
}, function (er) { | ||
@@ -95,14 +125,2 @@ if (er) return cb(er) | ||
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) { | ||
@@ -146,3 +164,9 @@ fs.readlink(p, function (er, r) { | ||
} | ||
if (!writable(s)) { | ||
fs.chmodSync(p, s.mode | 0222) | ||
} | ||
if (!s.isDirectory()) return fs.unlinkSync(p) | ||
fs.readdirSync(p).forEach(function (f) { | ||
@@ -149,0 +173,0 @@ rimrafSync(path.join(p, f)) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
160
2
7176
1
161
22