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:
authorForrest L Norvell <forrest@npmjs.com>2015-03-06 05:25:01 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-03-06 05:25:01 +0300
commit8885c4dfb618f2838930b5c5149abea300a762d6 (patch)
tree4b427f2c56e22dc06f90c578884719f89030f56e /node_modules/rimraf/rimraf.js
parent2abc3ee08f0cabc4e7bfd7b973c0b59dc44715ff (diff)
rimraf@2.3.1
* Glob arguments for better Windows support. * Handle bad symlinks properly. * Make maxBusyTries and emfileWait configurable * Also upgrade to glob@4.4.1
Diffstat (limited to 'node_modules/rimraf/rimraf.js')
-rw-r--r--node_modules/rimraf/rimraf.js155
1 files changed, 108 insertions, 47 deletions
diff --git a/node_modules/rimraf/rimraf.js b/node_modules/rimraf/rimraf.js
index eb96c46af..6dffdf064 100644
--- a/node_modules/rimraf/rimraf.js
+++ b/node_modules/rimraf/rimraf.js
@@ -4,11 +4,17 @@ rimraf.sync = rimrafSync
var assert = require("assert")
var path = require("path")
var fs = require("fs")
+var glob = require("glob")
+
+var globOpts = {
+ nosort: true,
+ nocomment: true,
+ nonegate: true,
+ silent: true
+}
// for EMFILE handling
var timeout = 0
-exports.EMFILE_MAX = 1000
-exports.BUSYTRIES_MAX = 3
var isWindows = (process.platform === "win32")
@@ -17,6 +23,7 @@ function defaults (options) {
'unlink',
'chmod',
'stat',
+ 'lstat',
'rmdir',
'readdir'
]
@@ -25,6 +32,9 @@ function defaults (options) {
m = m + 'Sync'
options[m] = options[m] || fs[m]
})
+
+ options.maxBusyTries = options.maxBusyTries || 3
+ options.emfileWait = options.emfileWait || 1000
}
function rimraf (p, options, cb) {
@@ -41,32 +51,54 @@ function rimraf (p, options, cb) {
if (!cb) throw new Error("No callback passed to rimraf()")
var busyTries = 0
- rimraf_(p, options, function CB (er) {
- if (er) {
- if (isWindows && (er.code === "EBUSY" || er.code === "ENOTEMPTY") &&
- busyTries < exports.BUSYTRIES_MAX) {
- busyTries ++
- var time = busyTries * 100
- // try again, with the same exact callback as this one.
- return setTimeout(function () {
- rimraf_(p, options, CB)
- }, time)
- }
+ var errState = null
+ var n = 0
- // this one won't happen if graceful-fs is used.
- if (er.code === "EMFILE" && timeout < exports.EMFILE_MAX) {
- return setTimeout(function () {
- rimraf_(p, options, CB)
- }, timeout ++)
- }
+ glob(p, globOpts, afterGlob)
- // already gone
- if (er.code === "ENOENT") er = null
- }
+ function next (er) {
+ errState = errState || er
+ if (--n === 0)
+ cb(errState)
+ }
- timeout = 0
- cb(er)
- })
+ function afterGlob (er, results) {
+ if (er)
+ return cb(er)
+
+ n = results.length
+ if (n === 0)
+ return cb()
+
+ results.forEach(function (p) {
+ rimraf_(p, options, function CB (er) {
+ if (er) {
+ if (isWindows && (er.code === "EBUSY" || er.code === "ENOTEMPTY") &&
+ busyTries < options.maxBusyTries) {
+ busyTries ++
+ var time = busyTries * 100
+ // try again, with the same exact callback as this one.
+ return setTimeout(function () {
+ rimraf_(p, options, CB)
+ }, time)
+ }
+
+ // this one won't happen if graceful-fs is used.
+ if (er.code === "EMFILE" && timeout < options.emfileWait) {
+ return setTimeout(function () {
+ rimraf_(p, options, CB)
+ }, timeout ++)
+ }
+
+ // already gone
+ if (er.code === "ENOENT") er = null
+ }
+
+ timeout = 0
+ next(er)
+ })
+ })
+ }
}
// Two possible strategies.
@@ -85,18 +117,28 @@ function rimraf_ (p, options, cb) {
assert(options)
assert(typeof cb === 'function')
- options.unlink(p, function (er) {
- if (er) {
- if (er.code === "ENOENT")
- return cb(null)
- if (er.code === "EPERM")
- return (isWindows)
- ? fixWinEPERM(p, options, er, cb)
- : rmdir(p, options, er, cb)
- if (er.code === "EISDIR")
- return rmdir(p, options, er, cb)
- }
- return cb(er)
+ // sunos lets the root user unlink directories, which is... weird.
+ // so we have to lstat here and make sure it's not a dir.
+ options.lstat(p, function (er, st) {
+ if (er && er.code === "ENOENT")
+ return cb(null)
+
+ if (st && st.isDirectory())
+ return rmdir(p, options, er, cb)
+
+ options.unlink(p, function (er) {
+ if (er) {
+ if (er.code === "ENOENT")
+ return cb(null)
+ if (er.code === "EPERM")
+ return (isWindows)
+ ? fixWinEPERM(p, options, er, cb)
+ : rmdir(p, options, er, cb)
+ if (er.code === "EISDIR")
+ return rmdir(p, options, er, cb)
+ }
+ return cb(er)
+ })
})
}
@@ -207,16 +249,35 @@ function rimrafSync (p, options) {
assert(p)
assert(options)
- try {
- options.unlinkSync(p)
- } catch (er) {
- if (er.code === "ENOENT")
- return
- if (er.code === "EPERM")
- return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
- if (er.code !== "EISDIR")
- throw er
- rmdirSync(p, options, er)
+ var results = glob.sync(p, globOpts)
+ if (!results.length)
+ return
+
+ for (var i = 0; i < results.length; i++) {
+ var p = results[i]
+
+ try {
+ var st = options.lstatSync(p)
+ } catch (er) {
+ if (er.code === "ENOENT")
+ return
+ }
+
+ try {
+ // sunos lets the root user unlink directories, which is... weird.
+ if (st && st.isDirectory())
+ rmdirSync(p, options, null)
+ else
+ options.unlinkSync(p)
+ } catch (er) {
+ if (er.code === "ENOENT")
+ return
+ if (er.code === "EPERM")
+ return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
+ if (er.code !== "EISDIR")
+ throw er
+ rmdirSync(p, options, er)
+ }
}
}