Skip to content

Commit 5523950

Browse files
cjihrigtargos
authored andcommittedDec 9, 2019
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 97e0efe commit 5523950

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)
Please sign in to comment.