Bug 697312: Don't write out extensions.ini if there are no extensions. r=Unfocused

This commit is contained in:
Dave Townsend 2011-11-03 18:30:43 -07:00
Родитель dc94045322
Коммит b32347b528
4 изменённых файлов: 76 добавлений и 32 удалений

Просмотреть файл

@ -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();
}
@ -4075,7 +4075,8 @@ var XPIDatabase = {
"type<>'theme' AND bootstrap=0",
getActiveTheme: "SELECT " + FIELDS_ADDON + " FROM addon WHERE " +
"internalName=:internalName AND type='theme'",
getThemes: "SELECT " + FIELDS_ADDON + " FROM addon WHERE type='theme'",
getThemes: "SELECT " + FIELDS_ADDON + " FROM addon WHERE type='theme' AND " +
"internalName<>:defaultSkin",
getAddonInLocation: "SELECT " + FIELDS_ADDON + " FROM addon WHERE id=:id " +
"AND location=:location",
@ -5470,50 +5471,73 @@ 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) {
if (addonsList.exists()) {
LOG("Deleting add-ons list");
addonsList.remove(false);
}
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);
}
}
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) {
stmt = null;
if (Prefs.getBoolPref(PREF_EM_DSS_ENABLED)) {
stmt = this.getStatement("getThemes");
stmt.params.defaultSkin = XPIProvider.defaultSkin;
}
else {
else if (XPIProvider.selectedSkin != XPIProvider.defaultSkin) {
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;
}
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(","));
}
else {
if (addonsList.exists()) {
LOG("Deleting add-ons list");
addonsList.remove(false);
}
Services.prefs.clearUserPref(PREF_EM_ENABLED_ADDONS);
}
}
};
function getHashStringForCrypto(aCrypto) {

Просмотреть файл

@ -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");

Просмотреть файл

@ -48,7 +48,7 @@ function run_test() {
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -76,7 +76,7 @@ function run_test_1(d, a) {
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -94,7 +94,7 @@ function run_test_1(d, a) {
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -121,7 +121,7 @@ function run_test_2() {
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -140,7 +140,7 @@ function run_test_2() {
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -158,7 +158,7 @@ function run_test_2() {
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -176,7 +176,7 @@ function run_test_2() {
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
@ -241,7 +241,7 @@ function check_test_2() {
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

Просмотреть файл

@ -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",