diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index bbfee92bc355..7a3e830dbb78 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -1759,7 +1759,7 @@ var XPIProvider = { } // Ensure any changes to the add-ons list are flushed to disk - XPIDatabase.writeAddonsList([]); + XPIDatabase.writeAddonsList(); Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, false); }, @@ -3034,8 +3034,8 @@ var XPIProvider = { // Check that the add-ons list still exists let addonsList = FileUtils.getFile(KEY_PROFILEDIR, [FILE_XPI_ADDONS_LIST], true); - if (!addonsList.exists()) { - LOG("Add-ons list is missing, recreating"); + if (addonsList.exists() == (state.length == 0)) { + LOG("Add-ons list is invalid, rebuilding"); XPIDatabase.writeAddonsList(); } @@ -5476,49 +5476,72 @@ var XPIDatabase = { * Writes out the XPI add-ons list for the platform to read. */ writeAddonsList: function XPIDB_writeAddonsList() { - LOG("Writing add-ons list"); Services.appinfo.invalidateCachesOnRestart(); + let addonsList = FileUtils.getFile(KEY_PROFILEDIR, [FILE_XPI_ADDONS_LIST], true); + if (!this.connection) { + try { + addonsList.remove(false); + LOG("Deleted add-ons list"); + } + catch (e) { + } + + Services.prefs.clearUserPref(PREF_EM_ENABLED_ADDONS); + return; + } let enabledAddons = []; let text = "[ExtensionDirs]\r\n"; let count = 0; - let stmt; + let fullCount = 0; - if (this.connection) { - stmt = this.getStatement("getActiveAddons"); + let stmt = this.getStatement("getActiveAddons"); - for (let row in resultRows(stmt)) { - text += "Extension" + (count++) + "=" + row.descriptor + "\r\n"; - enabledAddons.push(row.id + ":" + row.version); - } + for (let row in resultRows(stmt)) { + text += "Extension" + (count++) + "=" + row.descriptor + "\r\n"; + enabledAddons.push(row.id + ":" + row.version); } + fullCount += count; // The selected skin may come from an inactive theme (the default theme // when a lightweight theme is applied for example) text += "\r\n[ThemeDirs]\r\n"; - if (this.connection) { - if (Prefs.getBoolPref(PREF_EM_DSS_ENABLED)) { - stmt = this.getStatement("getThemes"); - } - else { - stmt = this.getStatement("getActiveTheme"); - stmt.params.internalName = XPIProvider.selectedSkin; - } + if (Prefs.getBoolPref(PREF_EM_DSS_ENABLED)) { + stmt = this.getStatement("getThemes"); + } + else { + stmt = this.getStatement("getActiveTheme"); + stmt.params.internalName = XPIProvider.selectedSkin; + } + + if (stmt) { count = 0; for (let row in resultRows(stmt)) { text += "Extension" + (count++) + "=" + row.descriptor + "\r\n"; enabledAddons.push(row.id + ":" + row.version); } + fullCount += count; } - var fos = FileUtils.openSafeFileOutputStream(addonsList); - fos.write(text, text.length); - FileUtils.closeSafeFileOutputStream(fos); + if (fullCount > 0) { + LOG("Writing add-ons list"); + var fos = FileUtils.openSafeFileOutputStream(addonsList); + fos.write(text, text.length); + FileUtils.closeSafeFileOutputStream(fos); - Services.prefs.setCharPref(PREF_EM_ENABLED_ADDONS, enabledAddons.join(",")); + Services.prefs.setCharPref(PREF_EM_ENABLED_ADDONS, enabledAddons.join(",")); + } + else { + if (addonsList.exists()) { + LOG("Deleting add-ons list"); + addonsList.remove(false); + } + + Services.prefs.clearUserPref(PREF_EM_ENABLED_ADDONS); + } } }; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index 6adc0520a0f5..8e7c7bc92144 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -129,6 +129,9 @@ function run_test() { file.append("extensions.sqlite"); do_check_false(file.exists()); + file.leafName = "extensions.ini"; + do_check_false(file.exists()); + run_test_1(); } @@ -175,6 +178,9 @@ function check_test_1() { file.append("extensions.sqlite"); do_check_true(file.exists()); + file.leafName = "extensions.ini"; + do_check_false(file.exists()); + AddonManager.getAllInstalls(function(installs) { // There should be no active installs now since the install completed and // doesn't require a restart. @@ -255,6 +261,10 @@ function run_test_3() { do_check_eq(getShutdownReason(), ADDON_DISABLE); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); + let file = gProfD.clone(); + file.append("extensions.ini"); + do_check_false(file.exists()); + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { do_check_neq(b1, null); do_check_eq(b1.version, "1.0"); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js index 3e4f112a1826..f4412a6bbcb9 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js @@ -136,6 +136,9 @@ function run_test() { file.append("extensions.sqlite"); do_check_false(file.exists()); + file.leafName = "extensions.ini"; + do_check_false(file.exists()); + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org", @@ -191,6 +194,9 @@ function run_test_1() { file.append("extensions.sqlite"); do_check_true(file.exists()); + file.leafName = "extensions.ini"; + do_check_true(file.exists()); + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org", @@ -292,6 +298,10 @@ function run_test_2() { check_startup_changes(AddonManager.STARTUP_CHANGE_ENABLED, []); do_check_true(gCachePurged); + var file = gProfD.clone(); + file.append("extensions.ini"); + do_check_true(file.exists()); + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org",