Bug 612393: Upgraded extensions get lost when downgrading. r=robstrong, a=blocks-final
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 21 Dec 2010 11:09:20 -0800
changeset 59564 a57900b40a7bdcd2933ae994f6fc624db1e63252
parent 59563 1edc1d75b7d47fce068bba0e18808ffa3790a3d1
child 59565 cdddfc399df358ee40e65afb307e4483ae5cada6
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersrobstrong, blocks-final
bugs612393
milestone2.0b9pre
Bug 612393: Upgraded extensions get lost when downgrading. r=robstrong, a=blocks-final
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_migrate1.js
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -78,16 +78,17 @@ const PREF_INSTALL_REQUIREBUILTINCERTS =
 const URI_EXTENSION_UPDATE_DIALOG     = "chrome://mozapps/content/extensions/update.xul";
 
 const DIR_EXTENSIONS                  = "extensions";
 const DIR_STAGE                       = "staged";
 const DIR_XPI_STAGE                   = "staged-xpis";
 const DIR_TRASH                       = "trash";
 
 const FILE_OLD_DATABASE               = "extensions.rdf";
+const FILE_OLD_CACHE                  = "extensions.cache";
 const FILE_DATABASE                   = "extensions.sqlite";
 const FILE_INSTALL_MANIFEST           = "install.rdf";
 const FILE_XPI_ADDONS_LIST            = "extensions.ini";
 
 const KEY_PROFILEDIR                  = "ProfD";
 const KEY_APPDIR                      = "XCurProcD";
 const KEY_TEMPDIR                     = "TmpD";
 
@@ -1754,17 +1755,17 @@ var XPIProvider = {
             fis.close();
           }
         }
 
         LOG("Processing install of " + id + " in " + aLocation.name);
         try {
           var addonInstallLocation = aLocation.installAddon(id, stageDirEntry,
                                                             existingAddonID);
-          if (id in aManifests[aLocation.name])
+          if (aManifests[aLocation.name][id])
             aManifests[aLocation.name][id]._sourceBundle = addonInstallLocation;
         }
         catch (e) {
           ERROR("Failed to install staged add-on " + id + " in " + aLocation.name,
                 e);
           delete aManifests[aLocation.name][id];
           continue;
         }
@@ -2369,22 +2370,30 @@ var XPIProvider = {
                                                          aAppChanged,
                                                          migrateData, null);
         }
         catch (e) {
           ERROR("Error processing file changes", e);
         }
       }
 
-      // When upgrading the app and using a custom skin make sure it is still
-      // compatible otherwise switch back the default
-      if (aAppChanged && this.currentSkin != this.defaultSkin) {
-        let oldSkin = XPIDatabase.getVisibleAddonForInternalName(this.currentSkin);
-        if (!oldSkin || oldSkin.appDisabled)
-          this.enableDefaultTheme();
+      if (aAppChanged) {
+        // When upgrading the app and using a custom skin make sure it is still
+        // compatible otherwise switch back the default
+        if (this.currentSkin != this.defaultSkin) {
+          let oldSkin = XPIDatabase.getVisibleAddonForInternalName(this.currentSkin);
+          if (!oldSkin || oldSkin.appDisabled)
+            this.enableDefaultTheme();
+        }
+
+        // When upgrading remove the old extensions cache to force older
+        // versions to rescan the entire list of extensions
+        let oldCache = FileUtils.getFile(KEY_PROFILEDIR, [FILE_OLD_CACHE], true);
+        if (oldCache.exists())
+          oldCache.remove(true);
       }
 
       // If the application crashed before completing any pending operations then
       // we should perform them now.
       if (extensionListChanged || hasPendingChanges) {
         LOG("Updating database with changes to installed add-ons");
         XPIDatabase.updateActiveAddons();
         XPIDatabase.commitTransaction();
@@ -3565,17 +3574,16 @@ var XPIDatabase = {
           let state = XPIProvider.getInstallLocationStates();
           XPIProvider.processFileChanges(state, {}, false, migrateData, activeBundles)
           // Make sure to update the active add-ons and add-ons list on shutdown
           Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, true);
           this.commitTransaction();
         }
         catch (e) {
           ERROR("Error processing file changes", e);
-          dump(e.stack);
           this.rollbackTransaction();
         }
       }
     }
 
     // If the database connection has a file open then it has the right schema
     // by now so make sure the preferences reflect that. If not then there is
     // an in-memory database open which means a problem opening and deleting the
--- a/toolkit/mozapps/extensions/test/xpcshell/test_migrate1.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate1.js
@@ -114,20 +114,29 @@ function run_test() {
 
   let addon7 = do_get_addon("test_migrate7");
   addon7.copyTo(stagedXPIs, "tmp.xpi");
   stagedXPIs = stagedXPIs.parent;
 
   let old = do_get_file("data/test_migrate.rdf");
   old.copyTo(gProfD, "extensions.rdf");
 
+  let oldCache = gProfD.clone();
+  oldCache.append("extensions.cache");
+  oldCache.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
+
   // Theme state is determined by the selected theme pref
   Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0");
 
+  Services.prefs.setCharPref("extensions.lastAppVersion", "1");
+
   startupManager();
+
+  do_check_false(oldCache.exists());
+
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",