rimraf 2.2.3 → 2.2.8
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/README.md +10 -6
- package/package.json +1 -4
- package/rimraf.js +112 -49
- package/test/run.sh +8 -2
- package/package/package.json +0 -19
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
`rm -rf` for node.
|
|
2
2
|
|
|
3
3
|
Install with `npm install rimraf`, or just drop rimraf.js somewhere.
|
|
4
4
|
|
|
@@ -9,11 +9,10 @@ Install with `npm install rimraf`, or just drop rimraf.js somewhere.
|
|
|
9
9
|
The callback will be called with an error if there is one. Certain
|
|
10
10
|
errors are handled for you:
|
|
11
11
|
|
|
12
|
-
* `EBUSY` -
|
|
13
|
-
before giving up.
|
|
14
|
-
* `
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* Windows: `EBUSY` and `ENOTEMPTY` - rimraf will back off a maximum of
|
|
13
|
+
`opts.maxBusyTries` times before giving up.
|
|
14
|
+
* `ENOENT` - If the file doesn't exist, rimraf will return
|
|
15
|
+
successfully, since your desired outcome is already the case.
|
|
17
16
|
|
|
18
17
|
## rimraf.sync
|
|
19
18
|
|
|
@@ -24,3 +23,8 @@ the async API. It's better.
|
|
|
24
23
|
|
|
25
24
|
If installed with `npm install rimraf -g` it can be used as a global
|
|
26
25
|
command `rimraf <path>` which is useful for cross platform support.
|
|
26
|
+
|
|
27
|
+
## mkdirp
|
|
28
|
+
|
|
29
|
+
If you need to create a directory recursively, check out
|
|
30
|
+
[mkdirp](https://github.com/substack/node-mkdirp).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rimraf",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
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/)",
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
"type": "MIT",
|
|
9
9
|
"url": "https://github.com/isaacs/rimraf/raw/master/LICENSE"
|
|
10
10
|
},
|
|
11
|
-
"optionalDependencies": {
|
|
12
|
-
"graceful-fs": "~2"
|
|
13
|
-
},
|
|
14
11
|
"repository": "git://github.com/isaacs/rimraf.git",
|
|
15
12
|
"scripts": {
|
|
16
13
|
"test": "cd test && bash run.sh"
|
package/rimraf.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
module.exports = rimraf
|
|
2
2
|
rimraf.sync = rimrafSync
|
|
3
3
|
|
|
4
|
+
var assert = require("assert")
|
|
4
5
|
var path = require("path")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
// optional dependency
|
|
9
|
-
fs = require("graceful-fs")
|
|
10
|
-
} catch (er) {
|
|
11
|
-
fs = require("fs")
|
|
12
|
-
}
|
|
6
|
+
var fs = require("fs")
|
|
13
7
|
|
|
14
8
|
// for EMFILE handling
|
|
15
9
|
var timeout = 0
|
|
@@ -18,11 +12,36 @@ exports.BUSYTRIES_MAX = 3
|
|
|
18
12
|
|
|
19
13
|
var isWindows = (process.platform === "win32")
|
|
20
14
|
|
|
21
|
-
function
|
|
15
|
+
function defaults (options) {
|
|
16
|
+
var methods = [
|
|
17
|
+
'unlink',
|
|
18
|
+
'chmod',
|
|
19
|
+
'stat',
|
|
20
|
+
'rmdir',
|
|
21
|
+
'readdir'
|
|
22
|
+
]
|
|
23
|
+
methods.forEach(function(m) {
|
|
24
|
+
options[m] = options[m] || fs[m]
|
|
25
|
+
m = m + 'Sync'
|
|
26
|
+
options[m] = options[m] || fs[m]
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function rimraf (p, options, cb) {
|
|
31
|
+
if (typeof options === 'function') {
|
|
32
|
+
cb = options
|
|
33
|
+
options = {}
|
|
34
|
+
}
|
|
35
|
+
assert(p)
|
|
36
|
+
assert(options)
|
|
37
|
+
assert(typeof cb === 'function')
|
|
38
|
+
|
|
39
|
+
defaults(options)
|
|
40
|
+
|
|
22
41
|
if (!cb) throw new Error("No callback passed to rimraf()")
|
|
23
42
|
|
|
24
43
|
var busyTries = 0
|
|
25
|
-
rimraf_(p, function CB (er) {
|
|
44
|
+
rimraf_(p, options, function CB (er) {
|
|
26
45
|
if (er) {
|
|
27
46
|
if (isWindows && (er.code === "EBUSY" || er.code === "ENOTEMPTY") &&
|
|
28
47
|
busyTries < exports.BUSYTRIES_MAX) {
|
|
@@ -30,14 +49,14 @@ function rimraf (p, cb) {
|
|
|
30
49
|
var time = busyTries * 100
|
|
31
50
|
// try again, with the same exact callback as this one.
|
|
32
51
|
return setTimeout(function () {
|
|
33
|
-
rimraf_(p, CB)
|
|
52
|
+
rimraf_(p, options, CB)
|
|
34
53
|
}, time)
|
|
35
54
|
}
|
|
36
55
|
|
|
37
56
|
// this one won't happen if graceful-fs is used.
|
|
38
57
|
if (er.code === "EMFILE" && timeout < exports.EMFILE_MAX) {
|
|
39
58
|
return setTimeout(function () {
|
|
40
|
-
rimraf_(p, CB)
|
|
59
|
+
rimraf_(p, options, CB)
|
|
41
60
|
}, timeout ++)
|
|
42
61
|
}
|
|
43
62
|
|
|
@@ -61,64 +80,91 @@ function rimraf (p, cb) {
|
|
|
61
80
|
//
|
|
62
81
|
// If anyone ever complains about this, then I guess the strategy could
|
|
63
82
|
// be made configurable somehow. But until then, YAGNI.
|
|
64
|
-
function rimraf_ (p, cb) {
|
|
65
|
-
|
|
83
|
+
function rimraf_ (p, options, cb) {
|
|
84
|
+
assert(p)
|
|
85
|
+
assert(options)
|
|
86
|
+
assert(typeof cb === 'function')
|
|
87
|
+
|
|
88
|
+
options.unlink(p, function (er) {
|
|
66
89
|
if (er) {
|
|
67
90
|
if (er.code === "ENOENT")
|
|
68
91
|
return cb(null)
|
|
69
92
|
if (er.code === "EPERM")
|
|
70
|
-
return (isWindows)
|
|
93
|
+
return (isWindows)
|
|
94
|
+
? fixWinEPERM(p, options, er, cb)
|
|
95
|
+
: rmdir(p, options, er, cb)
|
|
71
96
|
if (er.code === "EISDIR")
|
|
72
|
-
return rmdir(p, er, cb)
|
|
97
|
+
return rmdir(p, options, er, cb)
|
|
73
98
|
}
|
|
74
99
|
return cb(er)
|
|
75
100
|
})
|
|
76
101
|
}
|
|
77
102
|
|
|
78
|
-
function fixWinEPERM (p, er, cb) {
|
|
79
|
-
|
|
103
|
+
function fixWinEPERM (p, options, er, cb) {
|
|
104
|
+
assert(p)
|
|
105
|
+
assert(options)
|
|
106
|
+
assert(typeof cb === 'function')
|
|
107
|
+
if (er)
|
|
108
|
+
assert(er instanceof Error)
|
|
109
|
+
|
|
110
|
+
options.chmod(p, 666, function (er2) {
|
|
80
111
|
if (er2)
|
|
81
112
|
cb(er2.code === "ENOENT" ? null : er)
|
|
82
113
|
else
|
|
83
|
-
|
|
114
|
+
options.stat(p, function(er3, stats) {
|
|
84
115
|
if (er3)
|
|
85
116
|
cb(er3.code === "ENOENT" ? null : er)
|
|
86
117
|
else if (stats.isDirectory())
|
|
87
|
-
rmdir(p, er, cb)
|
|
118
|
+
rmdir(p, options, er, cb)
|
|
88
119
|
else
|
|
89
|
-
|
|
120
|
+
options.unlink(p, cb)
|
|
90
121
|
})
|
|
91
122
|
})
|
|
92
123
|
}
|
|
93
124
|
|
|
94
|
-
function fixWinEPERMSync (p,
|
|
125
|
+
function fixWinEPERMSync (p, options, er) {
|
|
126
|
+
assert(p)
|
|
127
|
+
assert(options)
|
|
128
|
+
if (er)
|
|
129
|
+
assert(er instanceof Error)
|
|
130
|
+
|
|
95
131
|
try {
|
|
96
|
-
|
|
132
|
+
options.chmodSync(p, 666)
|
|
97
133
|
} catch (er2) {
|
|
98
|
-
if (er2.code
|
|
134
|
+
if (er2.code === "ENOENT")
|
|
135
|
+
return
|
|
136
|
+
else
|
|
99
137
|
throw er
|
|
100
138
|
}
|
|
101
139
|
|
|
102
140
|
try {
|
|
103
|
-
var stats =
|
|
141
|
+
var stats = options.statSync(p)
|
|
104
142
|
} catch (er3) {
|
|
105
|
-
if (er3
|
|
143
|
+
if (er3.code === "ENOENT")
|
|
144
|
+
return
|
|
145
|
+
else
|
|
106
146
|
throw er
|
|
107
147
|
}
|
|
108
148
|
|
|
109
149
|
if (stats.isDirectory())
|
|
110
|
-
rmdirSync(p, er)
|
|
150
|
+
rmdirSync(p, options, er)
|
|
111
151
|
else
|
|
112
|
-
|
|
152
|
+
options.unlinkSync(p)
|
|
113
153
|
}
|
|
114
154
|
|
|
115
|
-
function rmdir (p, originalEr, cb) {
|
|
155
|
+
function rmdir (p, options, originalEr, cb) {
|
|
156
|
+
assert(p)
|
|
157
|
+
assert(options)
|
|
158
|
+
if (originalEr)
|
|
159
|
+
assert(originalEr instanceof Error)
|
|
160
|
+
assert(typeof cb === 'function')
|
|
161
|
+
|
|
116
162
|
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
|
117
163
|
// if we guessed wrong, and it's not a directory, then
|
|
118
164
|
// raise the original error.
|
|
119
|
-
|
|
120
|
-
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST"))
|
|
121
|
-
rmkids(p, cb)
|
|
165
|
+
options.rmdir(p, function (er) {
|
|
166
|
+
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
|
|
167
|
+
rmkids(p, options, cb)
|
|
122
168
|
else if (er && er.code === "ENOTDIR")
|
|
123
169
|
cb(originalEr)
|
|
124
170
|
else
|
|
@@ -126,22 +172,26 @@ function rmdir (p, originalEr, cb) {
|
|
|
126
172
|
})
|
|
127
173
|
}
|
|
128
174
|
|
|
129
|
-
function rmkids(p, cb) {
|
|
130
|
-
|
|
175
|
+
function rmkids(p, options, cb) {
|
|
176
|
+
assert(p)
|
|
177
|
+
assert(options)
|
|
178
|
+
assert(typeof cb === 'function')
|
|
179
|
+
|
|
180
|
+
options.readdir(p, function (er, files) {
|
|
131
181
|
if (er)
|
|
132
182
|
return cb(er)
|
|
133
183
|
var n = files.length
|
|
134
184
|
if (n === 0)
|
|
135
|
-
return
|
|
185
|
+
return options.rmdir(p, cb)
|
|
136
186
|
var errState
|
|
137
187
|
files.forEach(function (f) {
|
|
138
|
-
rimraf(path.join(p, f), function (er) {
|
|
188
|
+
rimraf(path.join(p, f), options, function (er) {
|
|
139
189
|
if (errState)
|
|
140
190
|
return
|
|
141
191
|
if (er)
|
|
142
192
|
return cb(errState = er)
|
|
143
193
|
if (--n === 0)
|
|
144
|
-
|
|
194
|
+
options.rmdir(p, cb)
|
|
145
195
|
})
|
|
146
196
|
})
|
|
147
197
|
})
|
|
@@ -150,36 +200,49 @@ function rmkids(p, cb) {
|
|
|
150
200
|
// this looks simpler, and is strictly *faster*, but will
|
|
151
201
|
// tie up the JavaScript thread and fail on excessively
|
|
152
202
|
// deep directory trees.
|
|
153
|
-
function rimrafSync (p) {
|
|
203
|
+
function rimrafSync (p, options) {
|
|
204
|
+
options = options || {}
|
|
205
|
+
defaults(options)
|
|
206
|
+
|
|
207
|
+
assert(p)
|
|
208
|
+
assert(options)
|
|
209
|
+
|
|
154
210
|
try {
|
|
155
|
-
|
|
211
|
+
options.unlinkSync(p)
|
|
156
212
|
} catch (er) {
|
|
157
213
|
if (er.code === "ENOENT")
|
|
158
214
|
return
|
|
159
215
|
if (er.code === "EPERM")
|
|
160
|
-
return isWindows ? fixWinEPERMSync(p, er) : rmdirSync(p, er)
|
|
216
|
+
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
|
|
161
217
|
if (er.code !== "EISDIR")
|
|
162
218
|
throw er
|
|
163
|
-
rmdirSync(p, er)
|
|
219
|
+
rmdirSync(p, options, er)
|
|
164
220
|
}
|
|
165
221
|
}
|
|
166
222
|
|
|
167
|
-
function rmdirSync (p, originalEr) {
|
|
223
|
+
function rmdirSync (p, options, originalEr) {
|
|
224
|
+
assert(p)
|
|
225
|
+
assert(options)
|
|
226
|
+
if (originalEr)
|
|
227
|
+
assert(originalEr instanceof Error)
|
|
228
|
+
|
|
168
229
|
try {
|
|
169
|
-
|
|
230
|
+
options.rmdirSync(p)
|
|
170
231
|
} catch (er) {
|
|
171
232
|
if (er.code === "ENOENT")
|
|
172
233
|
return
|
|
173
234
|
if (er.code === "ENOTDIR")
|
|
174
235
|
throw originalEr
|
|
175
|
-
if (er.code === "ENOTEMPTY" || er.code === "EEXIST")
|
|
176
|
-
rmkidsSync(p)
|
|
236
|
+
if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
|
|
237
|
+
rmkidsSync(p, options)
|
|
177
238
|
}
|
|
178
239
|
}
|
|
179
240
|
|
|
180
|
-
function rmkidsSync (p) {
|
|
181
|
-
|
|
182
|
-
|
|
241
|
+
function rmkidsSync (p, options) {
|
|
242
|
+
assert(p)
|
|
243
|
+
assert(options)
|
|
244
|
+
options.readdirSync(p).forEach(function (f) {
|
|
245
|
+
rimrafSync(path.join(p, f), options)
|
|
183
246
|
})
|
|
184
|
-
|
|
247
|
+
options.rmdirSync(p, options)
|
|
185
248
|
}
|
package/test/run.sh
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
set -e
|
|
3
|
+
code=0
|
|
3
4
|
for i in test-*.js; do
|
|
4
5
|
echo -n $i ...
|
|
5
6
|
bash setup.sh
|
|
6
7
|
node $i
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
if [ -d target ]; then
|
|
9
|
+
echo "fail"
|
|
10
|
+
code=1
|
|
11
|
+
else
|
|
12
|
+
echo "pass"
|
|
13
|
+
fi
|
|
9
14
|
done
|
|
10
15
|
rm -rf target
|
|
16
|
+
exit $code
|
package/package/package.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rimraf",
|
|
3
|
-
"version": "2.2.2",
|
|
4
|
-
"main": "rimraf.js",
|
|
5
|
-
"description": "A deep deletion module for node (like `rm -rf`)",
|
|
6
|
-
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
|
7
|
-
"license": {
|
|
8
|
-
"type": "MIT",
|
|
9
|
-
"url": "https://github.com/isaacs/rimraf/raw/master/LICENSE"
|
|
10
|
-
},
|
|
11
|
-
"optionalDependencies": {
|
|
12
|
-
"graceful-fs": "~2"
|
|
13
|
-
},
|
|
14
|
-
"repository": "git://github.com/isaacs/rimraf.git",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "cd test && bash run.sh"
|
|
17
|
-
},
|
|
18
|
-
"bin": "./bin.js"
|
|
19
|
-
}
|