Client code - Bug 1362267 - Replace requests are failing on Windows and falling back to normal updates. r=mhowell
authorRobert Strong <robert.bugzilla@gmail.com>
Fri, 05 May 2017 12:46:25 -0700
changeset 356786 24ecce36f4012f42ae0d672d0207e7589f16620d
parent 356785 91e80fe926250b6d2ce64cc955dc194bcaae0b3a
child 356787 dd650c37854b8944953d9b4bbf9ece2f23bdf410
push id89964
push userrstrong@mozilla.com
push dateFri, 05 May 2017 19:46:32 +0000
treeherdermozilla-inbound@24ecce36f401 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1362267
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Client code - Bug 1362267 - Replace requests are failing on Windows and falling back to normal updates. r=mhowell Restore chdir for replace requests in updater.cpp
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -2551,26 +2551,16 @@ UpdateThreadFunc(void *param)
       NS_tchar updatingDir[MAXPATHLEN];
       NS_tsnprintf(updatingDir, sizeof(updatingDir)/sizeof(updatingDir[0]),
                    NS_T("%s/updating"), gWorkingDirPath);
       ensure_remove_recursive(updatingDir);
     }
   }
 
   if (rv && (sReplaceRequest || sStagedUpdate)) {
-#ifdef XP_WIN
-    // On Windows, the current working directory of the process should be changed
-    // so that it's not locked.
-    if (sStagedUpdate) {
-      NS_tchar sysDir[MAX_PATH + 1] = { L'\0' };
-      if (GetSystemDirectoryW(sysDir, MAX_PATH + 1)) {
-        NS_tchdir(sysDir);
-      }
-    }
-#endif
     ensure_remove_recursive(gWorkingDirPath);
     // When attempting to replace the application, we should fall back
     // to non-staged updates in case of a failure.  We do this by
     // setting the status to pending, exiting the updater, and
     // launching the callback application.  The callback application's
     // startup path will see the pending status, and will start the
     // updater application again in order to apply the update without
     // staging.
@@ -3002,16 +2992,25 @@ int NS_main(int argc, NS_tchar **argv)
     }
   }
 #else
   if (pid > 0)
     waitpid(pid, nullptr, 0);
 #endif
 
 #ifdef XP_WIN
+  if (sReplaceRequest || sStagedUpdate) {
+    // On Windows, when performing a stage or replace request the current
+    // working directory for the process must be changed so it isn't locked.
+    NS_tchar sysDir[MAX_PATH + 1] = { L'\0' };
+    if (GetSystemDirectoryW(sysDir, MAX_PATH + 1)) {
+      NS_tchdir(sysDir);
+    }
+  }
+
 #ifdef MOZ_MAINTENANCE_SERVICE
   sUsingService = EnvHasValue("MOZ_USING_SERVICE");
   putenv(const_cast<char*>("MOZ_USING_SERVICE="));
 #endif
   // lastFallbackError keeps track of the last error for the service not being
   // used, in case of an error when fallback is not enabled we write the
   // error to the update.status file.
   // When fallback is disabled (MOZ_NO_SERVICE_FALLBACK does not exist) then