Backed out changeset f3cf78d7e62d (bug 853388)
authorTim Taubert <ttaubert@mozilla.com>
Fri, 09 Aug 2013 04:20:05 +0200
changeset 154745 a64c1ad76ba1b5e3b2631f86c7ae679eee78e9e3
parent 154744 bc2cb7f532f2fee494a5c9ef68407f9c2c0a0b52
child 154746 59a3d59d9fb7db15b980b8cdefec744ca957c799
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs853388
milestone26.0a1
backs outf3cf78d7e62dd8e21a0860ed3bd11259a00774f3
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
Backed out changeset f3cf78d7e62d (bug 853388)
toolkit/mozapps/extensions/Makefile.in
toolkit/mozapps/extensions/XPIProviderUtils.js
toolkit/mozapps/extensions/test/xpcshell/test_migrate2.js
toolkit/mozapps/extensions/test/xpcshell/test_migrate_max_version.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/mozapps/extensions/Makefile.in
+++ b/toolkit/mozapps/extensions/Makefile.in
@@ -10,17 +10,17 @@ VPATH     = @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 ifeq (,$(filter aurora beta release esr,$(MOZ_UPDATE_CHANNEL)))
 DEFINES += -DMOZ_COMPATIBILITY_NIGHTLY=1
 endif
 
 # This is used in multiple places, so is defined here to avoid it getting
 # out of sync.
-DEFINES += -DMOZ_EXTENSIONS_DB_SCHEMA=15
+DEFINES += -DMOZ_EXTENSIONS_DB_SCHEMA=14
 
 # Additional debugging info is exposed in debug builds, or by setting the
 # MOZ_EM_DEBUG environment variable when building.
 ifneq (,$(MOZ_EM_DEBUG))
 DEFINES += -DMOZ_EM_DEBUG=1
 else ifdef MOZ_DEBUG
 DEFINES += -DMOZ_EM_DEBUG=1
 endif
--- a/toolkit/mozapps/extensions/XPIProviderUtils.js
+++ b/toolkit/mozapps/extensions/XPIProviderUtils.js
@@ -38,18 +38,16 @@ const KEY_PROFILEDIR                  = 
 const FILE_DATABASE                   = "extensions.sqlite";
 const FILE_JSON_DB                    = "extensions.json";
 const FILE_OLD_DATABASE               = "extensions.rdf";
 const FILE_XPI_ADDONS_LIST            = "extensions.ini";
 
 // The value for this is in Makefile.in
 #expand const DB_SCHEMA                       = __MOZ_EXTENSIONS_DB_SCHEMA__;
 
-// The last version of DB_SCHEMA implemented in SQLITE
-const LAST_SQLITE_DB_SCHEMA           = 14;
 const PREF_DB_SCHEMA                  = "extensions.databaseSchema";
 const PREF_PENDING_OPERATIONS         = "extensions.pendingOperations";
 const PREF_EM_ENABLED_ADDONS          = "extensions.enabledAddons";
 const PREF_EM_DSS_ENABLED             = "extensions.dss.enabled";
 
 
 // Properties that only exist in the database
 const DB_METADATA        = ["syncGUID",
@@ -466,31 +464,36 @@ this.XPIDatabase = {
    *
    * @return false if there is no SQLITE database
    *         true and sets this.migrateData to null if the SQLITE DB exists
    *              but does not contain useful information
    *         true and sets this.migrateData to
    *              {location: {id1:{addon1}, id2:{addon2}}, location2:{...}, ...}
    *              if there is useful information
    */
-  getMigrateDataFromSQLITE: function XPIDB_getMigrateDataFromSQLITE() {
+  loadSqliteData: function XPIDB_loadSqliteData() {
     let connection = null;
     let dbfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_DATABASE], true);
+    if (!dbfile.exists()) {
+      return false;
+    }
     // Attempt to open the database
     try {
       connection = Services.storage.openUnsharedDatabase(dbfile);
     }
     catch (e) {
+      // exists but SQLITE can't open it
       WARN("Failed to open sqlite database " + dbfile.path + " for upgrade", e);
-      return null;
+      this.migrateData = null;
+      return true;
     }
     LOG("Migrating data from sqlite");
-    let migrateData = this.getMigrateDataFromDatabase(connection);
+    this.migrateData = this.getMigrateDataFromDatabase(connection);
     connection.close();
-    return migrateData;
+    return true;
   },
 
   /**
    * Opens and reads the database file, upgrading from old
    * databases or making a new DB if needed.
    *
    * The possibilities, in order of priority, are:
    * 1) Perfectly good, up to date database
@@ -570,39 +573,33 @@ this.XPIDatabase = {
       }
       finally {
         if (cstream)
           cstream.close();
       }
     }
     catch (e) {
       if (e.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
-        try {
-          let schemaVersion = Services.prefs.getIntPref(PREF_DB_SCHEMA);
-          if (schemaVersion <= LAST_SQLITE_DB_SCHEMA) {
-            // we should have an older SQLITE database
-            this.migrateData = this.getMigrateDataFromSQLITE();
-          }
-          // else we've upgraded before but the JSON file is gone, fall through
-          // and rebuild from scratch
-        }
-        catch(e) {
-          // No schema version pref means either a really old upgrade (RDF) or
-          // a new profile
+        // XXX re-implement logic to decide whether to upgrade database
+        // by checking the DB_SCHEMA_VERSION preference.
+        // Fall back to attempting database upgrades
+        WARN("Extensions database not found; attempting to upgrade");
+        // See if there is SQLITE to migrate from
+        if (!this.loadSqliteData()) {
+          // Nope, try RDF
           this.migrateData = this.getMigrateDataFromRDF();
         }
 
         this.rebuildDatabase(aRebuildOnError);
       }
       else {
         WARN("Extensions database " + this.jsonFile.path +
             " exists but is not readable; rebuilding in memory", e);
         // XXX open question - if we can overwrite at save time, should we, or should we
         // leave the locked database in case we can recover from it next time we start up?
-        // The old code made one attempt to remove the locked file before it rebuilt in memory
         this.lockedDatabase = true;
         // XXX TELEMETRY report when this happens?
         this.rebuildDatabase(aRebuildOnError);
       }
     }
     finally {
       if (fstream)
         fstream.close();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_migrate2.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate2.js
@@ -1,13 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-// Checks that we migrate data from SQLITE databases
+// Checks that we migrate data from future versions of the database
 // Note that since the database doesn't contain the foreignInstall field we
 // should just assume that no add-ons  in the user profile were foreignInstalls
 
 // Enable loading extensions from the user and system scopes
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
                           AddonManager.SCOPE_SYSTEM);
 
@@ -172,17 +172,17 @@ function run_test() {
   stmt.params.internal_id = internal_ids["addon6@tests.mozilla.org"];
   stmt.params.id = "xpcshell@tests.mozilla.org";
   stmt.params.minVersion = "0";
   stmt.params.maxVersion = "1";
   stmt.execute();
   stmt.finalize();
 
   db.schemaVersion = 10000;
-  Services.prefs.setIntPref("extensions.databaseSchema", 14);
+  Services.prefs.setIntPref("extensions.databaseSchema", 100);
   db.close();
 
   startupManager();
   check_startup_changes("installed", []);
   check_startup_changes("updated", []);
   check_startup_changes("uninstalled", []);
   check_startup_changes("disabled", []);
   check_startup_changes("enabled", []);
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/xpcshell/test_migrate_max_version.js
+++ /dev/null
@@ -1,102 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-// Checks that we don't migrate data from SQLITE if
-// the "extensions.databaseSchema" preference shows we've
-// already upgraded to JSON
-
-// Enable loading extensions from the user and system scopes
-Services.prefs.setIntPref("extensions.enabledScopes",
-                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
-                          AddonManager.SCOPE_SYSTEM);
-
-var addon1 = {
-  id: "addon1@tests.mozilla.org",
-  version: "1.0",
-  name: "Test 1",
-  targetApplications: [{
-    id: "xpcshell@tests.mozilla.org",
-    minVersion: "1",
-    maxVersion: "1"
-  }]
-};
-
-createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
-const profileDir = gProfD.clone();
-profileDir.append("extensions");
-
-function run_test() {
-  writeInstallRDFForExtension(addon1, profileDir);
-
-  // Write out a minimal database
-  let dbfile = gProfD.clone();
-  dbfile.append("extensions.sqlite");
-  let db = AM_Cc["@mozilla.org/storage/service;1"].
-           getService(AM_Ci.mozIStorageService).
-           openDatabase(dbfile);
-  db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
-                          "id TEXT, location TEXT, version TEXT, active INTEGER, " +
-                          "userDisabled INTEGER, installDate INTEGER");
-  db.createTable("targetApplication", "addon_internal_id INTEGER, " +
-                                      "id TEXT, minVersion TEXT, maxVersion TEXT");
-  let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
-                                ":version, :active, :userDisabled, :installDate)");
-
-  let internal_ids = {};
-
-  [["addon1@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"]
-   ].forEach(function(a) {
-    stmt.params.id = a[0];
-    stmt.params.location = a[1];
-    stmt.params.version = a[2];
-    stmt.params.active = a[3];
-    stmt.params.userDisabled = a[4];
-    stmt.params.installDate = a[5];
-    stmt.execute();
-    internal_ids[a[0]] = db.lastInsertRowID;
-  });
-  stmt.finalize();
-
-  db.schemaVersion = 15;
-  Services.prefs.setIntPref("extensions.databaseSchema", 14);
-  db.close();
-
-  startupManager();
-
-  AddonManager.getAddonByID("addon1@tests.mozilla.org",
-                            function check_before_rebuild (a1) {
-    // First check that it migrated OK once
-    // addon1 was disabled in the database
-    do_check_neq(a1, null);
-    do_check_true(a1.userDisabled);
-    do_check_false(a1.appDisabled);
-    do_check_false(a1.isActive);
-    do_check_false(a1.strictCompatibility);
-    do_check_false(a1.foreignInstall);
-
-    run_next_test();
-  });
-}
-
-// now shut down, remove the JSON database, 
-// start up again, and make sure the data didn't migrate this time
-add_test(function rebuild_again() {
-  shutdownManager();
-  gExtensionsJSON.remove(true);
-  startupManager();
-
-  AddonManager.getAddonByID("addon1@tests.mozilla.org",
-                            function check_after_rebuild(a1) {
-    // addon1 was rebuilt from extensions directory,
-    // so it appears enabled as a foreign install
-    do_check_neq(a1, null);
-    do_check_false(a1.userDisabled);
-    do_check_false(a1.appDisabled);
-    do_check_true(a1.isActive);
-    do_check_false(a1.strictCompatibility);
-    do_check_true(a1.foreignInstall);
-
-    run_next_test();
-  });
-});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -200,17 +200,16 @@ run-sequentially = Uses hardcoded ports 
 # Same as test_bootstrap.js
 skip-if = os == "android"
 [test_migrate1.js]
 [test_migrate2.js]
 [test_migrate3.js]
 [test_migrate4.js]
 [test_migrate5.js]
 [test_migrateAddonRepository.js]
-[test_migrate_max_version.js]
 [test_onPropertyChanged_appDisabled.js]
 [test_permissions.js]
 [test_plugins.js]
 [test_pluginchange.js]
 [test_pluginBlocklistCtp.js]
 # Bug 676992: test consistently fails on Android
 fail-if = os == "android"
 [test_pref_properties.js]