Skip to content

Commit ddc1a2f

Browse files
pgonzalRyanZim
authored andcommitted
Fix removeSync() to eliminate spurious ENOTEMPTY errors on Windows (#646)
Fix removeSync() to measure its retry interval in milliseconds instead of CPU cycles
1 parent ab254b1 commit ddc1a2f

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/remove/rimraf.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,24 @@ function rmkidsSync (p, options) {
290290
assert(options)
291291
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options))
292292

293-
// We only end up here once we got ENOTEMPTY at least once, and
294-
// at this point, we are guaranteed to have removed all the kids.
295-
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
296-
// try really hard to delete stuff on windows, because it has a
297-
// PROFOUNDLY annoying habit of not closing handles promptly when
298-
// files are deleted, resulting in spurious ENOTEMPTY errors.
299-
const retries = isWindows ? 100 : 1
300-
let i = 0
301-
do {
302-
let threw = true
303-
try {
304-
const ret = options.rmdirSync(p, options)
305-
threw = false
306-
return ret
307-
} finally {
308-
if (++i < retries && threw) continue // eslint-disable-line
309-
}
310-
} while (true)
293+
if (isWindows) {
294+
// We only end up here once we got ENOTEMPTY at least once, and
295+
// at this point, we are guaranteed to have removed all the kids.
296+
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
297+
// try really hard to delete stuff on windows, because it has a
298+
// PROFOUNDLY annoying habit of not closing handles promptly when
299+
// files are deleted, resulting in spurious ENOTEMPTY errors.
300+
const startTime = Date.now()
301+
do {
302+
try {
303+
const ret = options.rmdirSync(p, options)
304+
return ret
305+
} catch (er) { }
306+
} while (Date.now() - startTime < 500) // give up after 500ms
307+
} else {
308+
const ret = options.rmdirSync(p, options)
309+
return ret
310+
}
311311
}
312312

313313
module.exports = rimraf

0 commit comments

Comments
 (0)