rimraf 2.5.2 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin.js +13 -3
  2. package/package.json +3 -3
  3. package/rimraf.js +34 -6
package/bin.js CHANGED
@@ -4,16 +4,21 @@ var rimraf = require('./')
4
4
 
5
5
  var help = false
6
6
  var dashdash = false
7
+ var noglob = false
7
8
  var args = process.argv.slice(2).filter(function(arg) {
8
9
  if (dashdash)
9
10
  return !!arg
10
11
  else if (arg === '--')
11
12
  dashdash = true
13
+ else if (arg === '--no-glob' || arg === '-G')
14
+ noglob = true
15
+ else if (arg === '--glob' || arg === '-g')
16
+ noglob = false
12
17
  else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/))
13
18
  help = true
14
19
  else
15
20
  return !!arg
16
- });
21
+ })
17
22
 
18
23
  if (help || args.length === 0) {
19
24
  // If they didn't ask for help, then this is not a "success"
@@ -24,7 +29,9 @@ if (help || args.length === 0) {
24
29
  log('')
25
30
  log('Options:')
26
31
  log('')
27
- log(' -h, --help Display this usage info')
32
+ log(' -h, --help Display this usage info')
33
+ log(' -G, --no-glob Do not expand glob patterns in arguments')
34
+ log(' -g, --glob Expand glob patterns in arguments (default)')
28
35
  process.exit(help ? 0 : 1)
29
36
  } else
30
37
  go(0)
@@ -32,7 +39,10 @@ if (help || args.length === 0) {
32
39
  function go (n) {
33
40
  if (n >= args.length)
34
41
  return
35
- rimraf(args[n], function (er) {
42
+ var options = {}
43
+ if (noglob)
44
+ options = { glob: false }
45
+ rimraf(args[n], options, function (er) {
36
46
  if (er)
37
47
  throw er
38
48
  go(n+1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimraf",
3
- "version": "2.5.2",
3
+ "version": "2.6.1",
4
4
  "main": "rimraf.js",
5
5
  "description": "A deep deletion module for node (like `rm -rf`)",
6
6
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "bin": "./bin.js",
13
13
  "dependencies": {
14
- "glob": "^7.0.0"
14
+ "glob": "^7.0.5"
15
15
  },
16
16
  "files": [
17
17
  "LICENSE",
@@ -21,6 +21,6 @@
21
21
  ],
22
22
  "devDependencies": {
23
23
  "mkdirp": "^0.5.1",
24
- "tap": "^5.1.1"
24
+ "tap": "^10.1.2"
25
25
  }
26
26
  }
package/rimraf.js CHANGED
@@ -48,9 +48,9 @@ function rimraf (p, options, cb) {
48
48
 
49
49
  assert(p, 'rimraf: missing path')
50
50
  assert.equal(typeof p, 'string', 'rimraf: path should be a string')
51
- assert(options, 'rimraf: missing options')
52
- assert.equal(typeof options, 'object', 'rimraf: options should be object')
53
51
  assert.equal(typeof cb, 'function', 'rimraf: callback function required')
52
+ assert(options, 'rimraf: invalid options argument provided')
53
+ assert.equal(typeof options, 'object', 'rimraf: options should be object')
54
54
 
55
55
  defaults(options)
56
56
 
@@ -61,7 +61,7 @@ function rimraf (p, options, cb) {
61
61
  if (options.disableGlob || !glob.hasMagic(p))
62
62
  return afterGlob(null, [p])
63
63
 
64
- fs.lstat(p, function (er, stat) {
64
+ options.lstat(p, function (er, stat) {
65
65
  if (!er)
66
66
  return afterGlob(null, [p])
67
67
 
@@ -85,7 +85,7 @@ function rimraf (p, options, cb) {
85
85
  results.forEach(function (p) {
86
86
  rimraf_(p, options, function CB (er) {
87
87
  if (er) {
88
- if (isWindows && (er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
88
+ if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
89
89
  busyTries < options.maxBusyTries) {
90
90
  busyTries ++
91
91
  var time = busyTries * 100
@@ -135,6 +135,10 @@ function rimraf_ (p, options, cb) {
135
135
  if (er && er.code === "ENOENT")
136
136
  return cb(null)
137
137
 
138
+ // Windows can EPERM on stat. Life is suffering.
139
+ if (er && er.code === "EPERM" && isWindows)
140
+ fixWinEPERM(p, options, er, cb)
141
+
138
142
  if (st && st.isDirectory())
139
143
  return rmdir(p, options, er, cb)
140
144
 
@@ -269,7 +273,7 @@ function rimrafSync (p, options) {
269
273
  results = [p]
270
274
  } else {
271
275
  try {
272
- fs.lstatSync(p)
276
+ options.lstatSync(p)
273
277
  results = [p]
274
278
  } catch (er) {
275
279
  results = glob.sync(p, options.glob)
@@ -287,6 +291,10 @@ function rimrafSync (p, options) {
287
291
  } catch (er) {
288
292
  if (er.code === "ENOENT")
289
293
  return
294
+
295
+ // Windows can EPERM on stat. Life is suffering.
296
+ if (er.code === "EPERM" && isWindows)
297
+ fixWinEPERMSync(p, options, er)
290
298
  }
291
299
 
292
300
  try {
@@ -302,6 +310,7 @@ function rimrafSync (p, options) {
302
310
  return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
303
311
  if (er.code !== "EISDIR")
304
312
  throw er
313
+
305
314
  rmdirSync(p, options, er)
306
315
  }
307
316
  }
@@ -331,5 +340,24 @@ function rmkidsSync (p, options) {
331
340
  options.readdirSync(p).forEach(function (f) {
332
341
  rimrafSync(path.join(p, f), options)
333
342
  })
334
- options.rmdirSync(p, options)
343
+
344
+ // We only end up here once we got ENOTEMPTY at least once, and
345
+ // at this point, we are guaranteed to have removed all the kids.
346
+ // So, we know that it won't be ENOENT or ENOTDIR or anything else.
347
+ // try really hard to delete stuff on windows, because it has a
348
+ // PROFOUNDLY annoying habit of not closing handles promptly when
349
+ // files are deleted, resulting in spurious ENOTEMPTY errors.
350
+ var retries = isWindows ? 100 : 1
351
+ var i = 0
352
+ do {
353
+ var threw = true
354
+ try {
355
+ var ret = options.rmdirSync(p, options)
356
+ threw = false
357
+ return ret
358
+ } finally {
359
+ if (++i < retries && threw)
360
+ continue
361
+ }
362
+ } while (true)
335
363
  }