Bug 1140672 - Remove app update file migration code for Windows. r=spohl
authorRobert Strong <robert.bugzilla@gmail.com>
Mon, 09 Mar 2015 19:58:30 -0700
changeset 232778 06abaa2883e11e16eac29ec1e0a789f4d8255955
parent 232730 acae51c40eea4bcda31dd46e1ecf149c5270abd0
child 232779 3e4cfc16f693488240c1568def7de28d0f7ebccd
push id56670
push userkwierso@gmail.com
push dateTue, 10 Mar 2015 23:12:10 +0000
treeherdermozilla-inbound@fd8e079d6335 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1140672
milestone39.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
Bug 1140672 - Remove app update file migration code for Windows. r=spohl
toolkit/mozapps/update/moz.build
toolkit/mozapps/update/nsUpdateServiceStub.js
toolkit/mozapps/update/tests/unit_aus_update/updateRootDirMigration_win.js
toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
--- a/toolkit/mozapps/update/moz.build
+++ b/toolkit/mozapps/update/moz.build
@@ -34,20 +34,20 @@ if CONFIG['MOZ_UPDATER']:
     TEST_DIRS += ['tests']
 
     XPIDL_SOURCES += [
         'nsIUpdateService.idl',
     ]
 
     EXTRA_COMPONENTS += [
         'nsUpdateService.manifest',
+        'nsUpdateServiceStub.js',
     ]
 
     EXTRA_PP_COMPONENTS += [
         'nsUpdateService.js',
-        'nsUpdateServiceStub.js',
     ]
 
     EXTRA_JS_MODULES += [
       'UpdaterHealthProvider.jsm'
     ]
 
 JAR_MANIFESTS += ['jar.mn']
--- a/toolkit/mozapps/update/nsUpdateServiceStub.js
+++ b/toolkit/mozapps/update/nsUpdateServiceStub.js
@@ -1,179 +1,41 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-const Cu = Components.utils;
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
 
 const DIR_UPDATES         = "updates";
-const FILE_UPDATES_DB     = "updates.xml";
-const FILE_UPDATE_ACTIVE  = "active-update.xml";
-const FILE_LAST_LOG       = "last-update.log";
-const FILE_BACKUP_LOG     = "backup-update.log";
 const FILE_UPDATE_STATUS  = "update.status";
 
 const KEY_UPDROOT         = "UpdRootD";
 
-#ifdef XP_WIN
-
-const PREF_APP_UPDATE_MIGRATE_APP_DIR = "app.update.migrated.updateDir";
-
-
-function getTaskbarIDHash(rootKey, exePath, appInfoName) {
-  let registry = Cc["@mozilla.org/windows-registry-key;1"].
-                 createInstance(Ci.nsIWindowsRegKey);
-  try {
-    registry.open(rootKey, "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
-                  Ci.nsIWindowsRegKey.ACCESS_READ);
-    if (registry.hasValue(exePath)) {
-      return registry.readStringValue(exePath);
-    }
-  } catch (ex) {
-  } finally {
-    registry.close();
-  }
-  return undefined;
-};
-
-/*
- * Migrates old update directory files to the new update directory
- * which is based on a hash of the installation.
- */
-function migrateOldUpdateDir() {
-  // Get the old udpate root leaf dir. It is based on the sub directory of
-  // program files, or if the exe path is not inside program files, the appname.
-  var appinfo = Components.classes["@mozilla.org/xre/app-info;1"].
-                getService(Components.interfaces.nsIXULAppInfo).
-                QueryInterface(Components.interfaces.nsIXULRuntime);
-  var updateLeafName;
-  var programFiles = FileUtils.getFile("ProgF", []);
-  var exeFile = FileUtils.getFile("XREExeF", []);
-  if (exeFile.path.substring(0, programFiles.path.length).toLowerCase() ==
-      programFiles.path.toLowerCase()) {
-    updateLeafName = exeFile.parent.leafName;
-  } else {
-    updateLeafName = appinfo.name;
-  }
-
-  // Get the old update root dir
-  var oldUpdateRoot;
-  if (appinfo.vendor) {
-    oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.vendor,
-                                                      appinfo.name,
-                                                      updateLeafName], false);
-  } else {
-    oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.name,
-                                                      updateLeafName], false);
-  }
-
-  // Obtain the new update root
-  var newUpdateRoot = FileUtils.getDir("UpdRootD", [], true);
-
-  // If there is no taskbar ID then we want to retry this migration
-  // at a later time if the application gets a taskbar ID.
-  var taskbarID = getTaskbarIDHash(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
-                                   exeFile.parent.path, appinfo.name);
-  if (!taskbarID) {
-    taskbarID = getTaskbarIDHash(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-                                 exeFile.parent.path, appinfo.name);
-    if (!taskbarID) {
-      return;
-    }
-  }
-
-  Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, true);
-
-  // Sanity checks only to ensure we don't delete something we don't mean to.
-  if (oldUpdateRoot.path.toLowerCase() == newUpdateRoot.path.toLowerCase() ||
-      updateLeafName.length == 0) {
-    return;
-  }
-
-  // If the old update root doesn't exist then we have already migrated
-  // or else there is no work to do.
-  if (!oldUpdateRoot.exists()) {
-    return;
-  }
-
-  // Get an array of all of the files we want to migrate.
-  // We do this so we don't copy anything extra.
-  var filesToMigrate = [FILE_UPDATES_DB, FILE_UPDATE_ACTIVE,
-                        ["updates", FILE_LAST_LOG], ["updates", FILE_BACKUP_LOG],
-                        ["updates", "0", FILE_UPDATE_STATUS]];
-
-  // Move each of those files to the new directory
-  filesToMigrate.forEach(relPath => {
-    let oldFile = oldUpdateRoot.clone();
-    let newFile = newUpdateRoot.clone();
-    if (relPath instanceof Array) {
-      relPath.forEach(relPathPart => {
-        oldFile.append(relPathPart);
-        newFile.append(relPathPart);
-      });
-    } else {
-      oldFile.append(relPath);
-      newFile.append(relPath);
-    }
-
-    try {
-      if (!newFile.exists()) {
-        oldFile.moveTo(newFile.parent, newFile.leafName);
-      }
-    } catch (e) {
-      Components.utils.reportError(e);
-    }
-  });
-
-  oldUpdateRoot.remove(true);
-}
-#endif
-
 /**
  * Gets the specified directory at the specified hierarchy under the update root
  * directory without creating it if it doesn't exist.
  * @param   pathArray
  *          An array of path components to locate beneath the directory
  *          specified by |key|
  * @return  nsIFile object for the location specified.
  */
 function getUpdateDirNoCreate(pathArray) {
   return FileUtils.getDir(KEY_UPDROOT, pathArray, false);
 }
 
 function UpdateServiceStub() {
-#ifdef XP_WIN
-  // Don't attempt this migration more than once for perf reasons
-  var migrated = 0;
-  try {
-    migrated = Services.prefs.getBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR);
-  } catch (e) {
-  }
-
-  if (!migrated) {
-    try {
-      migrateOldUpdateDir();
-    } catch (e) {
-      Components.utils.reportError(e);
-    }
-  }
-#endif
-
   let statusFile = getUpdateDirNoCreate([DIR_UPDATES, "0"]);
   statusFile.append(FILE_UPDATE_STATUS);
   // If the update.status file exists then initiate post update processing.
   if (statusFile.exists()) {
-    let aus = Components.classes["@mozilla.org/updates/update-service;1"].
+    let aus = Cc["@mozilla.org/updates/update-service;1"].
               getService(Ci.nsIApplicationUpdateService).
               QueryInterface(Ci.nsIObserver);
     aus.observe(null, "post-update-processing", "");
   }
 }
 UpdateServiceStub.prototype = {
   observe: function(){},
   classID: Components.ID("{e43b0010-04ba-4da6-b523-1f92580bc150}"),
deleted file mode 100644
--- a/toolkit/mozapps/update/tests/unit_aus_update/updateRootDirMigration_win.js
+++ /dev/null
@@ -1,171 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-const PREF_APP_UPDATE_MIGRATE_APP_DIR = "app.update.migrated.updateDir";
-
-function clearTaskbarIDHash(exePath, appInfoName) {
-  let registry = Cc["@mozilla.org/windows-registry-key;1"].
-                 createInstance(Ci.nsIWindowsRegKey);
-  try {
-    registry.open(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-                  "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
-                  Ci.nsIWindowsRegKey.ACCESS_ALL);
-    registry.removeValue(exePath);
-  } catch (e) {
-  }
-  finally {
-    registry.close();
-  }
-}
-
-function setTaskbarIDHash(exePath, hash, appInfoName) {
-  let registry = Cc["@mozilla.org/windows-registry-key;1"].
-                 createInstance(Ci.nsIWindowsRegKey);
-  try {
-    registry.create(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-                    "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
-                    Ci.nsIWindowsRegKey.ACCESS_WRITE);
-    registry.writeStringValue(exePath, hash);
-  } catch (e) {
-  }
-  finally {
-    registry.close();
-  }
-};
-
-function getMigrated() {
-  let migrated = 0;
-  try {
-    migrated = Services.prefs.getBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR);
-  } catch (e) {
-  }
-  return migrated;
-}
-
-/* General Update Manager Tests */
-
-function run_test() {
-  setupTestCommon();
-
-  standardInit();
-
-  let appinfo = Cc["@mozilla.org/xre/app-info;1"].
-                getService(Ci.nsIXULAppInfo).
-                QueryInterface(Ci.nsIXULRuntime);
-
-   // Obtain the old update root leaf
-  let updateLeafName;
-  let exeFile = FileUtils.getFile(XRE_EXECUTABLE_FILE, []);
-  let programFiles = FileUtils.getFile("ProgF", []);
-  if (exeFile.path.substring(0, programFiles.path.length).toLowerCase() ==
-      programFiles.path.toLowerCase()) {
-    updateLeafName = exeFile.parent.leafName;
-  } else {
-    updateLeafName = appinfo.name;
-  }
-
-  // Obtain the old update root
-  let oldUpdateRoot;
-  if (appinfo.vendor) {
-    oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.vendor,
-                                                      appinfo.name,
-                                                      updateLeafName], false);
-  } else {
-    oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.name,
-                                                      updateLeafName], false);
-  }
-  // Obtain the new update root
-  let newUpdateRoot = FileUtils.getDir("UpdRootD", [], false);
-
-  ///////////////////////////////////////////////////////////
-  // Setting a taskbar ID without the old update dir existing should set the
-  // pref so a migration isn't retried.
-
-  // Remove the old and new update root directories
-  try {
-    oldUpdateRoot.remove(true);
-  } catch (e) {
-  }
-  try {
-    newUpdateRoot.remove(true);
-  } catch (e) {
-  }
-  Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
-  setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
-  initUpdateServiceStub();
-  do_check_eq(getMigrated(), 1);
-
-  ///////////////////////////////////////////////////////////
-  // An application without a taskbar ID should bail early without a pref
-  // being set, so that if a taskbar is set for the application, the migration
-  // will be retried.
-
-  Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
-  clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
-  initUpdateServiceStub();
-  do_check_eq(getMigrated(), 0);
-
-  ///////////////////////////////////////////////////////////
-  // Migrating files should work
-
-  Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
-  setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
-  let oldUpdateDirs = oldUpdateRoot.clone();
-  oldUpdateDirs.append("updates");
-  oldUpdateDirs.append("0");
-  oldUpdateDirs.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-
-  // Get an array of all of the files we want to migrate.
-  // We do this to create them in the old update directory.
-  let filesToMigrate = [FILE_UPDATES_DB, FILE_UPDATE_ACTIVE,
-                        ["updates", FILE_LAST_LOG], ["updates", FILE_BACKUP_LOG],
-                        ["updates", "0", FILE_UPDATE_STATUS]];
-  // Move each of those files to the new directory
-  filesToMigrate.forEach(relPath => {
-    let oldFile = oldUpdateRoot.clone();
-    if (relPath instanceof Array) {
-      relPath.forEach(relPathPart => {
-        oldFile.append(relPathPart);
-      });
-    } else {
-      oldFile.append(relPath);
-    }
-    oldFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE);
-  });
-  // Do the migration
-  initUpdateServiceStub();
-  doTestFinish();
-  return;
-  // Now verify that each of the files exist in the new update directory
-  filesToMigrate.forEach(relPath => {
-    let newFile = newUpdateRoot.clone();
-    let oldFile = oldUpdateRoot.clone();
-    if (relPath instanceof Array) {
-      relPath.forEach(relPathPart => {
-        newFile.append(relPathPart);
-        oldFile.append(relPathPart);
-      });
-    } else {
-      newFile.append(relPath);
-      oldFile.append(relPath);
-    }
-    // The file should be mimgrated, except for FILE_UPDATE_STATUS
-    // which gets consumed by post update after it is migrated..
-    if (newFile.leafName != FILE_UPDATE_STATUS) {
-      do_check_true(newFile.exists());
-    }
-    do_check_false(oldFile.exists());
-  });
-
-  doTestFinish();
-}
-
-function end_test() {
-  let appinfo = Cc["@mozilla.org/xre/app-info;1"].
-                getService(Ci.nsIXULAppInfo).
-                QueryInterface(Ci.nsIXULRuntime);
-  let exeFile = FileUtils.getFile(XRE_EXECUTABLE_FILE, []);
-  clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
-}
--- a/toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
+++ b/toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
@@ -32,12 +32,10 @@ skip-if = toolkit != 'gonk'
 skip-if = toolkit == 'gonk'
 reason = custom nsIUpdatePrompt
 [uiOnlyAllowOneWindow.js]
 skip-if = toolkit == 'gonk'
 reason = custom nsIUpdatePrompt
 [uiUnsupportedAlreadyNotified.js]
 skip-if = toolkit == 'gonk'
 reason = custom nsIUpdatePrompt
-[updateRootDirMigration_win.js]
-skip-if = os != 'win'
 [updateHealthReport.js]
 skip-if = ! healthreport