Backed out changeset 2cc97556735f (bug 1314177)

This commit is contained in:
Sebastian Hengst 2017-04-05 21:06:38 +02:00
Родитель 57a56e6831
Коммит 25f379b71a
1 изменённых файлов: 86 добавлений и 8 удалений

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

@ -8500,6 +8500,43 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
this.locked = false;
}
/**
* Removes the specified files or directories in the staging directory and
* then if the staging directory is empty attempts to remove it.
*
* @param aLeafNames
* An array of file or directory to remove from the directory, the
* array may be empty
*/
cleanStagingDir(aLeafNames = []) {
let dir = this.getStagingDir();
for (let name of aLeafNames) {
let file = dir.clone();
file.append(name);
recursiveRemove(file);
}
if (this._stagingDirLock > 0)
return;
let dirEntries = dir.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
try {
if (dirEntries.nextFile)
return;
} finally {
dirEntries.close();
}
try {
setFilePermissions(dir, FileUtils.PERMS_DIRECTORY);
dir.remove(false);
} catch (e) {
logger.warn("Failed to remove staging dir", e);
// Failing to remove the staging directory is ignorable
}
}
/**
* Gets the staging directory to put add-ons that are pending install and
* uninstall into.
@ -8522,12 +8559,35 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
}
requestStagingDir() {
this._stagingDirLock++;
if (this._stagingDirPromise)
return this._stagingDirPromise;
this._addonSet = SystemAddonInstallLocation._loadAddonSet();
if (this._addonSet.directory) {
this._directory = this._baseDir.clone();
this._directory.append(this._addonSet.directory);
}
return super.requestStagingDir();
OS.File.makeDir(this._directory.path);
let stagepath = OS.Path.join(this._directory.path, DIR_STAGE);
return this._stagingDirPromise = OS.File.makeDir(stagepath).then(null, (e) => {
if (e instanceof OS.File.Error && e.becauseExists)
return;
logger.error("Failed to create staging directory", e);
throw e;
});
}
releaseStagingDir() {
this._stagingDirLock--;
if (this._stagingDirLock == 0) {
this._stagingDirPromise = null;
this.cleanStagingDir();
}
return Promise.resolve();
}
/**
@ -8555,7 +8615,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
* @param {Object} aAddonSet - object containing schema, directory and set
* of system add-on IDs and versions.
*/
static _saveAddonSet(aAddonSet) {
_saveAddonSet(aAddonSet) {
Preferences.set(PREF_SYSTEM_ADDON_SET, JSON.stringify(aAddonSet));
}
@ -8640,7 +8700,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
// remove everything from the pref first, if uninstall
// fails then at least they will not be re-activated on
// next restart.
SystemAddonInstallLocation._saveAddonSet({ schema: 1, addons: {} });
this._saveAddonSet({ schema: 1, addons: {} });
// If this is running at app startup, the pref being cleared
// will cause later stages of startup to notice that the
@ -8660,7 +8720,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
}
}
/**
/**
* Removes any directories not currently in use or pending use after a
* restart. Any errors that happen here don't really matter as we'll attempt
* to cleanup again next time.
@ -8750,7 +8810,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
// Record the new upgrade directory.
let state = { schema: 1, directory: newDir.leafName, addons: {} };
SystemAddonInstallLocation._saveAddonSet(state);
this._saveAddonSet(state);
this._nextDir = newDir;
let location = this;
@ -8791,7 +8851,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
}
previousState = SystemAddonInstallLocation._loadAddonSet();
SystemAddonInstallLocation._saveAddonSet(state);
this._saveAddonSet(state);
let blockers = aAddons.filter(
addon => AddonManagerPrivate.hasUpgradeListener(addon.id)
@ -8805,7 +8865,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
} catch (e) {
// Roll back to previous upgrade set (if present) on restart.
if (previousState) {
SystemAddonInstallLocation._saveAddonSet(previousState);
this._saveAddonSet(previousState);
}
// Otherwise, roll back to built-in set on restart.
// TODO try to do these restartlessly
@ -8824,7 +8884,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
* Resumes upgrade of a previously-delayed add-on set.
*/
async resumeAddonSet(installs) {
async function resumeAddon(install) {
function resumeAddon(install) {
install.state = AddonManager.STATE_DOWNLOADED;
install.installLocation.releaseStagingDir();
install.install();
@ -9016,6 +9076,24 @@ class WinRegInstallLocation extends DirectoryInstallLocation {
return this._name;
}
/**
* Gets the scope of this install location.
*/
get scope() {
return this._scope;
}
/**
* Gets an array of nsIFiles for add-ons installed in this location.
*/
getAddonLocations() {
let locations = new Map();
for (let id in this._IDToFileMap) {
locations.set(id, this._IDToFileMap[id].clone());
}
return locations;
}
/**
* @see DirectoryInstallLocation
*/