From 362a704df6ec2b4079cf7abf8a0329a6958c6f20 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Tue, 15 Nov 2011 11:22:48 -0800 Subject: [PATCH] Bug 697312: Don't write out extensions.ini if there are no extensions. r=Unfocused --- toolkit/mozapps/extensions/XPIProvider.jsm | 69 ++++++++++++------- .../test/xpcshell/test_bootstrap.js | 10 +++ .../extensions/test/xpcshell/test_startup.js | 10 +++ 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index bbfee92bc35..7a3e830dbb7 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 6adc0520a0f..8e7c7bc9214 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 3e4f112a182..f4412a6bbcb 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",