Bug 1314177 - remove redundancy in install location classes r=aswan

MozReview-Commit-ID: H4dTeU3N8zI

--HG--
extra : rebase_source : 60ee8229b551264be7f1e8ece0496ae544e9995a
extra : source : 5f39a4daef03c7d7111fabcb04ee23f2fb2ea534
This commit is contained in:
Robert Helmer 2017-03-28 12:29:53 -07:00
Родитель 37141d9e47
Коммит 9a052e8063
1 изменённых файлов: 10 добавлений и 86 удалений

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

@ -8500,43 +8500,6 @@ 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.
@ -8559,35 +8522,12 @@ 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);
}
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();
return super.requestStagingDir();
}
/**
@ -8615,7 +8555,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
* @param {Object} aAddonSet - object containing schema, directory and set
* of system add-on IDs and versions.
*/
_saveAddonSet(aAddonSet) {
static _saveAddonSet(aAddonSet) {
Preferences.set(PREF_SYSTEM_ADDON_SET, JSON.stringify(aAddonSet));
}
@ -8700,7 +8640,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.
this._saveAddonSet({ schema: 1, addons: {} });
SystemAddonInstallLocation._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
@ -8720,7 +8660,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.
@ -8810,7 +8750,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
// Record the new upgrade directory.
let state = { schema: 1, directory: newDir.leafName, addons: {} };
this._saveAddonSet(state);
SystemAddonInstallLocation._saveAddonSet(state);
this._nextDir = newDir;
let location = this;
@ -8851,7 +8791,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
}
previousState = SystemAddonInstallLocation._loadAddonSet();
this._saveAddonSet(state);
SystemAddonInstallLocation._saveAddonSet(state);
let blockers = aAddons.filter(
addon => AddonManagerPrivate.hasUpgradeListener(addon.id)
@ -8865,7 +8805,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
} catch (e) {
// Roll back to previous upgrade set (if present) on restart.
if (previousState) {
this._saveAddonSet(previousState);
SystemAddonInstallLocation._saveAddonSet(previousState);
}
// Otherwise, roll back to built-in set on restart.
// TODO try to do these restartlessly
@ -8884,7 +8824,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
* Resumes upgrade of a previously-delayed add-on set.
*/
async resumeAddonSet(installs) {
function resumeAddon(install) {
async function resumeAddon(install) {
install.state = AddonManager.STATE_DOWNLOADED;
install.installLocation.releaseStagingDir();
install.install();
@ -9005,6 +8945,8 @@ class WinRegInstallLocation extends DirectoryInstallLocation {
* The scope of add-ons installed in this location
*/
constructor(aName, aRootKey, aScope) {
super(aName, undefined, aScope);
this.locked = true;
this._name = aName;
this._rootKey = aRootKey;
@ -9076,24 +9018,6 @@ 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
*/