Bug 760027 - Attempt to retry moving the installation directory when performing the replace stage of an update 10 times; r=strong
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 31 May 2012 15:40:07 -0400
changeset 97733 1a28fcd25143cc6382d03d7db6396597e1c3a467
parent 97732 30babf8e5573ac625372476fa5d7bc59b5b4a07c
child 97734 f24ce56de72f08504fdd7ba7390ada0b398164d7
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstrong
bugs760027
milestone15.0a1
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.
toolkit/mozapps/update/updater/updater.cpp
--- 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);