Skip to content

Commit 4e05bf0

Browse files
cjihrigtargos
authored andcommitted
fs: add synchronous retries to rimraf
This commit gives the synchronous version of rimraf the same linear retry logic as the asynchronous version. Prior to this commit, sync rimraf kept retrying the operation as soon as possible until maxRetries was reached. PR-URL: #30785 Fixes: #30580 Refs: #30569 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent e1eb6a6 commit 4e05bf0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/internal/fs/rimraf.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
} = require('fs');
2222
const { join } = require('path');
2323
const { setTimeout } = require('timers');
24+
const { sleep } = require('internal/util');
2425
const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']);
2526
const retryErrorCodes = new Set(
2627
['EBUSY', 'EMFILE', 'ENFILE', 'ENOTEMPTY', 'EPERM']);
@@ -208,10 +209,13 @@ function _rmdirSync(path, options, originalErr) {
208209
rimrafSync(join(path, child), options);
209210
});
210211

211-
for (let i = 0; i < options.maxRetries + 1; i++) {
212+
for (let i = 1; i <= options.maxRetries + 1; i++) {
212213
try {
213214
return rmdirSync(path, options);
214-
} catch {} // Ignore errors.
215+
} catch {
216+
if (options.retryDelay > 0)
217+
sleep(i * options.retryDelay);
218+
}
215219
}
216220
}
217221
}

0 commit comments

Comments
 (0)