rimraf 2.1.0 → 2.1.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimraf",
3
- "version": "2.1.0",
3
+ "version": "2.1.4",
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/)",
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/isaacs/rimraf/raw/master/LICENSE"
10
10
  },
11
11
  "optionalDependencies": {
12
- "graceful-fs": "~1.1"
12
+ "graceful-fs": "~1"
13
13
  },
14
14
  "repository": "git://github.com/isaacs/rimraf.git",
15
15
  "scripts": {
package/rimraf.js CHANGED
@@ -48,7 +48,7 @@ function rimraf (p, cb) {
48
48
  }
49
49
 
50
50
  // Two possible strategies.
51
- // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM
51
+ // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
52
52
  // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
53
53
  //
54
54
  // Both result in an extra syscall when you guess wrong. However, there
@@ -62,13 +62,27 @@ function rimraf_ (p, cb) {
62
62
  fs.unlink(p, function (er) {
63
63
  if (er && er.code === "ENOENT")
64
64
  return cb()
65
- if (er && er.code === "EPERM")
66
- return rmdir(p, cb)
65
+ if (er && (er.code === "EPERM" || er.code === "EISDIR"))
66
+ return rmdir(p, er, cb)
67
67
  return cb(er)
68
68
  })
69
69
  }
70
70
 
71
- function rmdir (p, cb) {
71
+ function rmdir (p, originalEr, cb) {
72
+ // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
73
+ // if we guessed wrong, and it's not a directory, then
74
+ // raise the original error.
75
+ fs.rmdir(p, function (er) {
76
+ if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST"))
77
+ rmkids(p, cb)
78
+ else if (er && er.code === "ENOTDIR")
79
+ cb(originalEr)
80
+ else
81
+ cb(er)
82
+ })
83
+ }
84
+
85
+ function rmkids(p, cb) {
72
86
  fs.readdir(p, function (er, files) {
73
87
  if (er)
74
88
  return cb(er)
@@ -98,11 +112,21 @@ function rimrafSync (p) {
98
112
  } catch (er) {
99
113
  if (er.code === "ENOENT")
100
114
  return
101
- if (er.code !== "EPERM")
115
+ if (er.code !== "EPERM" && er.code !== "EISDIR")
102
116
  throw er
103
- fs.readdirSync(p).forEach(function (f) {
104
- rimrafSync(path.join(p, f))
105
- })
106
- fs.rmdirSync(p)
117
+ try {
118
+ fs.rmdirSync(p)
119
+ } catch (er2) {
120
+ if (er2.code === "ENOENT")
121
+ return
122
+ if (er2.code === "ENOTDIR")
123
+ throw er
124
+ if (er2.code === "ENOTEMPTY") {
125
+ fs.readdirSync(p).forEach(function (f) {
126
+ rimrafSync(path.join(p, f))
127
+ })
128
+ fs.rmdirSync(p)
129
+ }
130
+ }
107
131
  }
108
132
  }
File without changes