Bug 760027 - Attempt to retry moving the installation directory when performing the replace stage of an update 10 times; r=strong
This will hopefully give the applications which might have a handle to some
file in that directory open a chance to close them up so that the replace
operation would finish successfully.
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -1810,16 +1810,33 @@ ProcessReplaceRequest()
// directory exists, we will fail to rename sourceDir.
// No need to error check here because if this fails, we will fail in the
// next step anyways.
ensure_remove_recursive(tmpDir);
LOG(("Begin moving sourceDir (" LOG_S ") to tmpDir (" LOG_S ")\n",
sourceDir, tmpDir));
int rv = rename_file(sourceDir, tmpDir, true);
+#ifdef XP_WIN
+ // On Windows, if Firefox is launched using the shortcut, it will hold a handle
+ // to its installation directory open, which might not get released in time.
+ // Therefore we wait a little bit here to see if the handle is released.
+ // If it's not released, we just fail to perform the replace request.
+ const int max_retries = 10;
+ int retries = 0;
+ while (rv == WRITE_ERROR && (retries++ < max_retries)) {
+ LOG(("PerformReplaceRequest: sourceDir rename attempt %d failed. " \
+ "File: " LOG_S ". Last error: %d, err: %d\n", retries,
+ sourceDir, GetLastError(), rv));
+
+ Sleep(100);
+
+ rv = rename_file(sourceDir, tmpDir, true);
+ }
+#endif
if (rv) {
LOG(("Moving sourceDir to tmpDir failed, err: %d\n", rv));
return rv;
}
LOG(("Begin moving newDir (" LOG_S ") to sourceDir (" LOG_S ")\n",
newDir, sourceDir));
rv = rename_file(newDir, sourceDir, true);