Part 1 - Bug 951662 - change background to staging for consistency. r=bbondy
authorRobert Strong <robert.bugzilla@gmail.com>
Sun, 12 Jan 2014 13:44:41 -0800
changeset 179071 2377adfa7f5cf39b923cbf1d12b5bd1a817263a0
parent 179070 b35dc4d2e1b9509ea58e0aa55ea5f861b2b6eafb
child 179072 b1631d3a6042e45228caeeb64728ec65f7f42a48
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs951662
milestone29.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
Part 1 - Bug 951662 - change background to staging for consistency. r=bbondy
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -293,17 +293,17 @@ private:
 #endif
 
 //-----------------------------------------------------------------------------
 
 static NS_tchar* gSourcePath;
 static NS_tchar gDestinationPath[MAXPATHLEN];
 static ArchiveReader gArchiveReader;
 static bool gSucceeded = false;
-static bool sBackgroundUpdate = false;
+static bool sStagedUpdate = false;
 static bool sReplaceRequest = false;
 static bool sUsingService = false;
 static bool sIsOSUpdate = false;
 
 #ifdef XP_WIN
 // The current working directory specified in the command line.
 static NS_tchar* gDestPath;
 static NS_tchar gCallbackRelPath[MAXPATHLEN];
@@ -901,17 +901,17 @@ static int backup_discard(const NS_tchar
 
   // Nothing to discard
   if (NS_taccess(backup, F_OK)) {
     return OK;
   }
 
   int rv = ensure_remove(backup);
 #if defined(XP_WIN)
-  if (rv && !sBackgroundUpdate && !sReplaceRequest) {
+  if (rv && !sStagedUpdate && !sReplaceRequest) {
     LOG(("backup_discard: unable to remove: " LOG_S, backup));
     NS_tchar path[MAXPATHLEN];
     GetTempFileNameW(DELETE_DIR, L"moz", 0, path);
     if (rename_file(backup, path)) {
       LOG(("backup_discard: failed to rename file:" LOG_S ", dst:" LOG_S,
            backup, path));
       return WRITE_ERROR;
     }
@@ -1764,17 +1764,17 @@ WriteStatusFile(const char* aStatus)
 
 static void
 WriteStatusFile(int status)
 {
   const char *text;
 
   char buf[32];
   if (status == OK) {
-    if (sBackgroundUpdate) {
+    if (sStagedUpdate) {
       text = "applied\n";
     } else {
       text = "succeeded\n";
     }
   } else {
     snprintf(buf, sizeof(buf)/sizeof(buf[0]), "failed: %d\n", status);
     text = buf;
   }
@@ -1853,17 +1853,17 @@ IsUpdateStatusSucceeded(bool &isSucceede
  * @param installDir Out parameter for specifying the installation directory.
  * @return true if successful, false otherwise.
  */
 template <size_t N>
 static bool
 GetInstallationDir(NS_tchar (&installDir)[N])
 {
   NS_tsnprintf(installDir, N, NS_T("%s"), gDestinationPath);
-  if (!sBackgroundUpdate && !sReplaceRequest) {
+  if (!sStagedUpdate && !sReplaceRequest) {
     // no need to do any further processing
     return true;
   }
 
   NS_tchar *slash = (NS_tchar *) NS_tstrrchr(installDir, NS_SLASH);
   // Make sure we're not looking at a trailing slash
   if (slash && slash[1] == NS_T('\0')) {
     *slash = NS_T('\0');
@@ -1911,17 +1911,17 @@ CopyInstallDirToDestDir()
 #endif
 #endif
 
   return ensure_copy_recursive(installDir, gDestinationPath, skiplist);
 }
 
 /*
  * Replace the application installation directory with the destination
- * directory in order to finish a background update task
+ * directory in order to finish a staged update task
  *
  * @return 0 if successful, an error code otherwise.
  */
 static int
 ProcessReplaceRequest()
 {
   // The replacement algorithm is like this:
   // 1. Move sourceDir to tmpDir.  In case of failure, abort.
@@ -2195,17 +2195,17 @@ UpdateThreadFunc(void *param)
 
 #ifdef MOZ_VERIFY_MAR_SIGNATURE
     if (rv == OK) {
       rv = gArchiveReader.VerifySignature();
     }
 
     if (rv == OK) {
       NS_tchar installDir[MAXPATHLEN];
-      if (sBackgroundUpdate) {
+      if (sStagedUpdate) {
         if (!GetInstallationDir(installDir)) {
           rv = NO_INSTALLDIR_ERROR;
         }
       } else {
         NS_tstrcpy(installDir, gDestinationPath);
       }
       if (rv == OK) {
         NS_tchar updateSettingsPath[MAX_TEXT_LEN];
@@ -2220,17 +2220,17 @@ UpdateThreadFunc(void *param)
         }
 
         rv = gArchiveReader.VerifyProductInformation(MARStrings.MARChannelID,
                                                      MOZ_APP_VERSION);
       }
     }
 #endif
 
-    if (rv == OK && sBackgroundUpdate && !sIsOSUpdate) {
+    if (rv == OK && sStagedUpdate && !sIsOSUpdate) {
       rv = CopyInstallDirToDestDir();
     }
 
     if (rv == OK) {
       rv = DoUpdate();
       gArchiveReader.Close();
     }
   }
@@ -2393,34 +2393,34 @@ int NS_main(int argc, NS_tchar **argv)
 #endif
   if (argc > 3) {
 #ifdef XP_WIN
     pid = _wtoi64(argv[3]);
 #else
     pid = atoi(argv[3]);
 #endif
     if (pid == -1) {
-      // This is a signal from the parent process that the updater should work
-      // in the background.
-      sBackgroundUpdate = true;
+      // This is a signal from the parent process that the updater should stage
+      // the update.
+      sStagedUpdate = true;
     } else if (NS_tstrstr(argv[3], NS_T("/replace"))) {
-      // We're processing a request to replace a version of the application
-      // with an updated version applied in the background.
+      // We're processing a request to replace the application with a staged
+      // update.
       sReplaceRequest = true;
     }
   }
 
   if (getenv("MOZ_OS_UPDATE")) {
     sIsOSUpdate = true;
     putenv(const_cast<char*>("MOZ_OS_UPDATE="));
   }
 
   if (sReplaceRequest) {
     // If we're attempting to replace the application, try to append to the
-    // log generated when staging the background update.
+    // log generated when staging the staged update.
     NS_tchar installDir[MAXPATHLEN];
     if (!GetInstallationDir(installDir)) {
       fprintf(stderr, "Could not get the installation directory\n");
       return 1;
     }
 
 #ifdef XP_WIN
     NS_tchar* logDir = gSourcePath;
@@ -2440,18 +2440,18 @@ int NS_main(int argc, NS_tchar **argv)
     LogInit(gSourcePath, NS_T("update.log"));
   }
 
   if (!WriteStatusFile("applying")) {
     LOG(("failed setting status to 'applying'"));
     return 1;
   }
 
-  if (sBackgroundUpdate) {
-    LOG(("Performing a background update"));
+  if (sStagedUpdate) {
+    LOG(("Performing a staged update"));
   } else if (sReplaceRequest) {
     LOG(("Performing a replace request"));
   }
 
 #ifdef MOZ_WIDGET_GONK
   const char *prioEnv = getenv("MOZ_UPDATER_PRIO");
   if (prioEnv) {
     int32_t prioVal;
@@ -2530,20 +2530,20 @@ int NS_main(int argc, NS_tchar **argv)
   // we will instead fallback to not using the service and display a UAC prompt.
   int lastFallbackError = FALLBACKKEY_UNKNOWN_ERROR;
 
   // Launch a second instance of the updater with the runas verb on Windows
   // when write access is denied to the installation directory.
   HANDLE updateLockFileHandle = INVALID_HANDLE_VALUE;
   NS_tchar elevatedLockFilePath[MAXPATHLEN] = {NS_T('\0')};
   if (!sUsingService &&
-      (argc > callbackIndex || sBackgroundUpdate || sReplaceRequest)) {
+      (argc > callbackIndex || sStagedUpdate || sReplaceRequest)) {
     NS_tchar updateLockFilePath[MAXPATHLEN];
-    if (sBackgroundUpdate) {
-      // When updating in the background, the lock file is:
+    if (sStagedUpdate) {
+      // When staging an update, the lock file is:
       // $INSTALLDIR\updated.update_in_progress.lock
       NS_tsnprintf(updateLockFilePath,
                    sizeof(updateLockFilePath)/sizeof(updateLockFilePath[0]),
                    NS_T("%s.update_in_progress.lock"), gDestinationPath);
     } else if (sReplaceRequest) {
       // When processing a replace request, the lock file is:
       // $INSTALLDIR\..\moz_update_in_progress.lock
       NS_tchar installDir[MAXPATHLEN];
@@ -2551,31 +2551,31 @@ int NS_main(int argc, NS_tchar **argv)
         return 1;
       }
       NS_tchar *slash = (NS_tchar *) NS_tstrrchr(installDir, NS_SLASH);
       *slash = NS_T('\0');
       NS_tsnprintf(updateLockFilePath,
                    sizeof(updateLockFilePath)/sizeof(updateLockFilePath[0]),
                    NS_T("%s\\moz_update_in_progress.lock"), installDir);
     } else {
-      // In the old non-background update case, the lock file is:
+      // In the non-staging update case, the lock file is:
       // $INSTALLDIR\$APPNAME.exe.update_in_progress.lock
       NS_tsnprintf(updateLockFilePath,
                    sizeof(updateLockFilePath)/sizeof(updateLockFilePath[0]),
                    NS_T("%s.update_in_progress.lock"), argv[callbackIndex]);
     }
 
     // The update_in_progress.lock file should only exist during an update. In
     // case it exists attempt to remove it and exit if that fails to prevent
     // simultaneous updates occurring.
     if (!_waccess(updateLockFilePath, F_OK) &&
         NS_tremove(updateLockFilePath) != 0) {
-      // Try to fall back to the old way of doing updates if a background
+      // Try to fall back to the old way of doing updates if a staged
       // update fails.
-      if (sBackgroundUpdate || sReplaceRequest) {
+      if (sStagedUpdate || sReplaceRequest) {
         // Note that this could fail, but if it does, there isn't too much we
         // can do in order to recover anyways.
         WriteStatusFile("pending");
       }
       LOG(("Update already in progress! Exiting"));
       return 1;
     }
 
@@ -2696,18 +2696,18 @@ int NS_main(int argc, NS_tchar **argv)
       if (useService) {
         // If the update couldn't be started, then set useService to false so
         // we do the update the old way.
         DWORD ret = LaunchServiceSoftwareUpdateCommand(argc, (LPCWSTR *)argv);
         useService = (ret == ERROR_SUCCESS);
         // If the command was launched then wait for the service to be done.
         if (useService) {
           bool showProgressUI = false;
-          // Never show the progress UI for background updates
-          if (!sBackgroundUpdate) {
+          // Never show the progress UI when staging updates.
+          if (!sStagedUpdate) {
             // We need to call this separately instead of allowing ShowProgressUI
             // to initialize the strings because the service will move the
             // ini file out of the way when running updater.
             showProgressUI = !InitProgressUIStrings();
           }
 
           // Wait for the service to stop for 5 seconds.  If the service
           // has still not stopped then show an indeterminate progress bar.
@@ -2728,37 +2728,35 @@ int NS_main(int argc, NS_tchar **argv)
             lastFallbackError = FALLBACKKEY_SERVICE_NO_STOP_ERROR;
             useService = false;
           }
         } else {
           lastFallbackError = FALLBACKKEY_LAUNCH_ERROR;
         }
       }
 
-      // If we could not use the service in the background update case,
-      // we need to make sure that we will never show a UAC prompt!
-      // In this case, we would just set the status to pending and will
-      // apply the update at the next startup.
-      if (!useService && sBackgroundUpdate) {
+      // If the service can't be used when staging and update, make sure that
+      // the UAC prompt is not shown! In this case, just set the status to
+      // pending and the update will be applied during the next startup.
+      if (!useService && sStagedUpdate) {
         if (updateLockFileHandle != INVALID_HANDLE_VALUE) {
           CloseHandle(updateLockFileHandle);
         }
         WriteStatusPending(gSourcePath);
         return 0;
       }
 
       // If we started the service command, and it finished, check the
       // update.status file to make sure it succeeded, and if it did
       // we need to manually start the PostUpdate process from the
       // current user's session of this unelevated updater.exe the
       // current process is running as.
-      // Note that we don't need to do this if we're just staging the
-      // update in the background, as the PostUpdate step runs when
-      // performing the replacing in that case.
-      if (useService && !sBackgroundUpdate) {
+      // Note that we don't need to do this if we're just staging the update,
+      // as the PostUpdate step runs when performing the replacing in that case.
+      if (useService && !sStagedUpdate) {
         bool updateStatusSucceeded = false;
         if (IsUpdateStatusSucceeded(updateStatusSucceeded) && 
             updateStatusSucceeded) {
           if (!LaunchWinPostProcess(installDir, gSourcePath, false, nullptr)) {
             fprintf(stderr, "The post update process which runs as the user"
                     " for service update could not be launched.");
           }
         }
@@ -2843,19 +2841,19 @@ int NS_main(int argc, NS_tchar **argv)
   {
     GonkAutoMounter mounter;
     if (mounter.GetAccess() != MountAccess::ReadWrite) {
       WriteStatusFile(FILESYSTEM_MOUNT_READWRITE_ERROR);
       return 1;
     }
 #endif
 
-  if (sBackgroundUpdate) {
-    // For background updates, we want to blow away the old installation
-    // directory and create it from scratch.
+  if (sStagedUpdate) {
+    // When staging updates, blow away the old installation directory and create
+    // it from scratch.
     ensure_remove_recursive(gDestinationPath);
   }
   if (!sReplaceRequest) {
     // Change current directory to the directory where we need to apply the update.
     if (NS_tchdir(gDestinationPath) != 0) {
       // Try to create the destination directory if it doesn't exist
       int rv = NS_tmkdir(gDestinationPath, 0755);
       if (rv == OK && errno != EEXIST) {
@@ -3048,48 +3046,48 @@ int NS_main(int argc, NS_tchar **argv)
                             argv + callbackIndex,
                             sUsingService);
           return 1;
         }
       }
     }
   }
 
-  // DELETE_DIR is not required in the case of background updates.
-  if (!sBackgroundUpdate && !sReplaceRequest) {
+  // DELETE_DIR is not required when staging an update.
+  if (!sStagedUpdate && !sReplaceRequest) {
     // The directory to move files that are in use to on Windows. This directory
     // will be deleted after the update is finished or on OS reboot using
     // MoveFileEx if it contains files that are in use.
     if (NS_taccess(DELETE_DIR, F_OK)) {
       NS_tmkdir(DELETE_DIR, 0755);
     }
   }
 #endif /* XP_WIN */
 
   // Run update process on a background thread.  ShowProgressUI may return
   // before QuitProgressUI has been called, so wait for UpdateThreadFunc to
-  // terminate.  Avoid showing the progress UI for background updates.
+  // terminate.  Avoid showing the progress UI when staging an update.
   Thread t;
   if (t.Run(UpdateThreadFunc, nullptr) == 0) {
-    if (!sBackgroundUpdate && !sReplaceRequest) {
+    if (!sStagedUpdate && !sReplaceRequest) {
       ShowProgressUI();
     }
   }
   t.Join();
 
 #ifdef XP_WIN
   if (argc > callbackIndex && !sReplaceRequest) {
     if (callbackFile != INVALID_HANDLE_VALUE) {
       CloseHandle(callbackFile);
     }
     // Remove the copy of the callback executable.
     NS_tremove(gCallbackBackupPath);
   }
 
-  if (!sBackgroundUpdate && !sReplaceRequest && _wrmdir(DELETE_DIR)) {
+  if (!sStagedUpdate && !sReplaceRequest && _wrmdir(DELETE_DIR)) {
     LOG(("NS_main: unable to remove directory: " LOG_S ", err: %d",
          DELETE_DIR, errno));
     // The directory probably couldn't be removed due to it containing files
     // that are in use and will be removed on OS reboot. The call to remove the
     // directory on OS reboot is done after the calls to remove the files so the
     // files are removed first on OS reboot since the directory must be empty
     // for the directory removal to be successful. The MoveFileEx call to remove
     // the directory on OS reboot will fail if the process doesn't have write