Skip to content

Commit b0f690b

Browse files
committed
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.
1 parent eac3f0a commit b0f690b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/fs/rimraf.js

+5-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,12 @@ 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+
sleep(i * options.retryDelay);
217+
}
215218
}
216219
}
217220
}

0 commit comments

Comments
 (0)