From 33fbe78c3d173d1308468b3297556fd03c6c7b30 Mon Sep 17 00:00:00 2001 From: RyanZim Date: Mon, 10 Jul 2017 11:14:16 -0400 Subject: [PATCH] Apply upstream rimraf fixes https://github.com/isaacs/rimraf/commit/e8b10a79c25e84f2a017e8a38b0725d8a0b259d3 https://github.com/isaacs/rimraf/commit/d53235de863cfb00f691456288fcf3abbced7f6c https://github.com/isaacs/rimraf/commit/e8cd6853ba5cd47c53073af5bc9c17f88457bed4 --- lib/remove/rimraf.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/remove/rimraf.js b/lib/remove/rimraf.js index 28d4aeb0..15924c37 100644 --- a/lib/remove/rimraf.js +++ b/lib/remove/rimraf.js @@ -42,7 +42,7 @@ function rimraf (p, options, cb) { rimraf_(p, options, function CB (er) { if (er) { - if (isWindows && (er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') && + if ((er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') && busyTries < options.maxBusyTries) { busyTries++ let time = busyTries * 100 @@ -289,7 +289,25 @@ function rmkidsSync (p, options) { assert(p) assert(options) options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options)) - options.rmdirSync(p, 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) } module.exports = rimraf