mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
Fix: Retry rmdirSync on Windows for up to 1 second if files still exist. Fixes issue #49
This commit is contained in:
parent
3611190124
commit
520f4952e0
18
src/rm.js
18
src/rm.js
@ -48,7 +48,23 @@ function rmdirSyncRecursive(dir, force) {
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = fs.rmdirSync(dir);
|
||||
var start = Date.now();
|
||||
while (true) {
|
||||
try {
|
||||
result = fs.rmdirSync(dir);
|
||||
break;
|
||||
} catch(er) {
|
||||
if (process.platform === "win32" && (er.code === "ENOTEMPTY" || er.code === "EBUSY" || er.code === "EPERM" )) {
|
||||
// Retry on windows, sometimes it takes a little time before all the files in the directory
|
||||
// are gone
|
||||
if (Date.now() - start > 1000) throw er;
|
||||
} else if(er.code === "ENOENT") {
|
||||
break;
|
||||
} else {
|
||||
throw er;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
common.error('could not remove directory (code '+e.code+'): ' + dir, true);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user