Skip to content

Commit 29e269f

Browse files
committed
If the first rm -rf attempt fails to delete everything, make
a second attempt before reporting an error to the caller. Sometimes we fail to delete all of the contents of Firefox’s temporary profile on quit. I think this is caused by a race: we attempt the `rm -rf` before Firefox has fully shutdown, and files get rewritten after we delete them.
1 parent 3f313d1 commit 29e269f

File tree

1 file changed

+16
-7
lines changed
  • javascript/node/selenium-webdriver/io

1 file changed

+16
-7
lines changed

javascript/node/selenium-webdriver/io/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,22 @@ var PATH_SEPARATOR = process.platform === 'win32' ? ';' : ':';
3737
*/
3838
exports.rmDir = function(path) {
3939
return new promise.Promise(function(fulfill, reject) {
40-
rimraf(path, function(err) {
41-
if (err) {
42-
reject(err);
43-
} else {
44-
fulfill();
45-
}
46-
});
40+
var numAttempts = 0;
41+
attemptRm();
42+
function attemptRm() {
43+
numAttempts += 1;
44+
rimraf(path, function(err) {
45+
if (err) {
46+
if (err.code === 'ENOTEMPTY' && numAttempts < 2) {
47+
attemptRm();
48+
return;
49+
}
50+
reject(err);
51+
} else {
52+
fulfill();
53+
}
54+
});
55+
}
4756
});
4857
};
4958

0 commit comments

Comments
 (0)