diff options
author | Nitzan Uziely <linkgoron@gmail.com> | 2021-05-14 02:26:20 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-05-25 17:18:05 +0300 |
commit | f9447b71a6b458adbb265f8a5fd38ebf41bc97a4 (patch) | |
tree | 17532057b74f3c3f73f568cca2e995d7dadcffad /lib | |
parent | fa7cdd6fc9dffa8139f9350f54959b01bf7a1151 (diff) |
fs: fix rmsync error swallowing
fix rmsync swallowing errors instead of throwing them.
fixes: https://github.com/nodejs/node/issues/38683
fixes: https://github.com/nodejs/node/issues/34580
PR-URL: https://github.com/nodejs/node/pull/38684
Fixes: https://github.com/nodejs/node/issues/38683
Fixes: https://github.com/nodejs/node/issues/34580
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/fs/rimraf.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 675c2448c45..84f32dc6bb9 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -219,6 +219,11 @@ function _unlinkSync(path, options) { i < tries && options.retryDelay > 0) { sleep(i * options.retryDelay); + } else if (err.code === 'ENOENT') { + // The file is already gone. + return; + } else if (i === tries) { + throw err; } } } @@ -231,8 +236,9 @@ function _rmdirSync(path, options, originalErr) { } catch (err) { if (err.code === 'ENOENT') return; - if (err.code === 'ENOTDIR') - throw originalErr; + if (err.code === 'ENOTDIR') { + throw originalErr || err; + } if (notEmptyErrorCodes.has(err.code)) { // Removing failed. Try removing all children and then retrying the @@ -259,10 +265,17 @@ function _rmdirSync(path, options, originalErr) { i < tries && options.retryDelay > 0) { sleep(i * options.retryDelay); + } else if (err.code === 'ENOENT') { + // The file is already gone. + return; + } else if (i === tries) { + throw err; } } } } + + throw originalErr || err; } } |