Fix: Retry rmdirSync on Windows for up to 1 second if files still exist. Fixes issue #49

This commit is contained in:
Andrei Alecu 2015-01-11 13:44:57 +02:00
parent 3611190124
commit 520f4952e0

View File

@ -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);
}