Skip to content

Commit

Permalink
Fix removeSync() to eliminate spurious ENOTEMPTY errors on Windows (#646
Browse files Browse the repository at this point in the history
)

Fix removeSync() to measure its retry interval in milliseconds instead of CPU cycles
  • Loading branch information
pgonzal authored and RyanZim committed Nov 7, 2018
1 parent ab254b1 commit ddc1a2f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/remove/rimraf.js
Expand Up @@ -290,24 +290,24 @@ function rmkidsSync (p, options) {
assert(options)
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options))

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

module.exports = rimraf
Expand Down

0 comments on commit ddc1a2f

Please sign in to comment.