зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1358846: Part 5 - Clean up some path manipulation code. r=rhelmer
MozReview-Commit-ID: ArgurF3QVSw --HG-- extra : rebase_source : 5aac4694bf2d4e2d151a0704daaf94b22b726f9f
This commit is contained in:
Родитель
273fc8c0fb
Коммит
1f911b06b8
|
@ -612,8 +612,7 @@ SafeInstallOperation.prototype = {
|
||||||
if (aCopy) {
|
if (aCopy) {
|
||||||
newFile.copyTo(aTargetDirectory, null);
|
newFile.copyTo(aTargetDirectory, null);
|
||||||
// copyTo does not update the nsIFile with the new.
|
// copyTo does not update the nsIFile with the new.
|
||||||
newFile = aTargetDirectory.clone();
|
newFile = getFile(aFile.leafName, aTargetDirectory);
|
||||||
newFile.append(aFile.leafName);
|
|
||||||
// Windows roaming profiles won't properly sync directories if a new file
|
// Windows roaming profiles won't properly sync directories if a new file
|
||||||
// has an older lastModifiedTime than a previous file, so update.
|
// has an older lastModifiedTime than a previous file, so update.
|
||||||
newFile.lastModifiedTime = Date.now();
|
newFile.lastModifiedTime = Date.now();
|
||||||
|
@ -635,8 +634,7 @@ SafeInstallOperation.prototype = {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newDir = aTargetDirectory.clone();
|
let newDir = getFile(aDirectory.leafName, aTargetDirectory);
|
||||||
newDir.append(aDirectory.leafName);
|
|
||||||
try {
|
try {
|
||||||
newDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
newDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -777,8 +775,7 @@ SafeInstallOperation.prototype = {
|
||||||
if (move.isMoveTo) {
|
if (move.isMoveTo) {
|
||||||
move.newFile.moveTo(move.oldDir.parent, move.oldDir.leafName);
|
move.newFile.moveTo(move.oldDir.parent, move.oldDir.leafName);
|
||||||
} else if (move.newFile.isDirectory() && !move.newFile.isSymlink()) {
|
} else if (move.newFile.isDirectory() && !move.newFile.isSymlink()) {
|
||||||
let oldDir = move.oldFile.parent.clone();
|
let oldDir = getFile(move.oldFile.leafName, move.oldFile.parent);
|
||||||
oldDir.append(move.oldFile.leafName);
|
|
||||||
oldDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
oldDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
||||||
} else if (!move.oldFile) {
|
} else if (!move.oldFile) {
|
||||||
// No old file means this was a copied file
|
// No old file means this was a copied file
|
||||||
|
@ -990,8 +987,7 @@ function getExternalType(aType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getManifestFileForDir(aDir) {
|
function getManifestFileForDir(aDir) {
|
||||||
let file = aDir.clone();
|
let file = getFile(FILE_RDF_MANIFEST, aDir);
|
||||||
file.append(FILE_RDF_MANIFEST);
|
|
||||||
if (file.exists() && file.isFile())
|
if (file.exists() && file.isFile())
|
||||||
return file;
|
return file;
|
||||||
file.leafName = FILE_WEB_MANIFEST;
|
file.leafName = FILE_WEB_MANIFEST;
|
||||||
|
@ -1565,23 +1561,20 @@ var loadManifestFromDir = Task.async(function*(aDir, aInstallLocation) {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
let iconFile = aDir.clone();
|
let iconFile = getFile("icon.png", aDir);
|
||||||
iconFile.append("icon.png");
|
|
||||||
|
|
||||||
if (iconFile.exists()) {
|
if (iconFile.exists()) {
|
||||||
addon.icons[32] = "icon.png";
|
addon.icons[32] = "icon.png";
|
||||||
addon.icons[48] = "icon.png";
|
addon.icons[48] = "icon.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
let icon64File = aDir.clone();
|
let icon64File = getFile("icon64.png", aDir);
|
||||||
icon64File.append("icon64.png");
|
|
||||||
|
|
||||||
if (icon64File.exists()) {
|
if (icon64File.exists()) {
|
||||||
addon.icons[64] = "icon64.png";
|
addon.icons[64] = "icon64.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = aDir.clone();
|
let file = getFile("chrome.manifest", aDir);
|
||||||
file.append("chrome.manifest");
|
|
||||||
let chromeManifest = ChromeManifestParser.parseSync(Services.io.newFileURI(file));
|
let chromeManifest = ChromeManifestParser.parseSync(Services.io.newFileURI(file));
|
||||||
addon.hasBinaryComponents = ChromeManifestParser.hasType(chromeManifest,
|
addon.hasBinaryComponents = ChromeManifestParser.hasType(chromeManifest,
|
||||||
"binary-component");
|
"binary-component");
|
||||||
|
@ -3832,8 +3825,7 @@ this.XPIProvider = {
|
||||||
aManifests[location.name][id] = null;
|
aManifests[location.name][id] = null;
|
||||||
let existingAddonID = id;
|
let existingAddonID = id;
|
||||||
|
|
||||||
let jsonfile = stagingDir.clone();
|
let jsonfile = getFile(`${id}.json`, stagingDir);
|
||||||
jsonfile.append(id + ".json");
|
|
||||||
// Assume this was a foreign install if there is no cached metadata file
|
// Assume this was a foreign install if there is no cached metadata file
|
||||||
let foreignInstall = !jsonfile.exists();
|
let foreignInstall = !jsonfile.exists();
|
||||||
let addon;
|
let addon;
|
||||||
|
@ -5571,8 +5563,7 @@ this.XPIProvider = {
|
||||||
// automatically uninstalled on shutdown anyway so there is no need to
|
// automatically uninstalled on shutdown anyway so there is no need to
|
||||||
// do this for them.
|
// do this for them.
|
||||||
if (aAddon._installLocation.name != KEY_APP_TEMPORARY) {
|
if (aAddon._installLocation.name != KEY_APP_TEMPORARY) {
|
||||||
let stage = aAddon._installLocation.getStagingDir();
|
let stage = getFile(aAddon.id, aAddon._installLocation.getStagingDir());
|
||||||
stage.append(aAddon.id);
|
|
||||||
if (!stage.exists())
|
if (!stage.exists())
|
||||||
stage.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
stage.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
@ -5852,8 +5843,7 @@ class AddonInstall {
|
||||||
break;
|
break;
|
||||||
case AddonManager.STATE_INSTALLED:
|
case AddonManager.STATE_INSTALLED:
|
||||||
logger.debug("Cancelling install of " + this.addon.id);
|
logger.debug("Cancelling install of " + this.addon.id);
|
||||||
let xpi = this.installLocation.getStagingDir();
|
let xpi = getFile(`${this.addon.id}.xpi`, this.installLocation.getStagingDir());
|
||||||
xpi.append(this.addon.id + ".xpi");
|
|
||||||
flushJarCache(xpi);
|
flushJarCache(xpi);
|
||||||
this.installLocation.cleanStagingDir([this.addon.id, this.addon.id + ".xpi",
|
this.installLocation.cleanStagingDir([this.addon.id, this.addon.id + ".xpi",
|
||||||
this.addon.id + ".json"]);
|
this.addon.id + ".json"]);
|
||||||
|
@ -6174,8 +6164,7 @@ class AddonInstall {
|
||||||
// remove any previously staged files
|
// remove any previously staged files
|
||||||
yield this.unstageInstall(stagedAddon);
|
yield this.unstageInstall(stagedAddon);
|
||||||
|
|
||||||
stagedAddon.append(this.addon.id);
|
stagedAddon.append(`${this.addon.id}.xpi`);
|
||||||
stagedAddon.leafName = this.addon.id + ".xpi";
|
|
||||||
|
|
||||||
installedUnpacked = yield this.stageInstall(requiresRestart, stagedAddon, isUpgrade);
|
installedUnpacked = yield this.stageInstall(requiresRestart, stagedAddon, isUpgrade);
|
||||||
|
|
||||||
|
@ -6347,22 +6336,15 @@ class AddonInstall {
|
||||||
/**
|
/**
|
||||||
* Removes any previously staged upgrade.
|
* Removes any previously staged upgrade.
|
||||||
*/
|
*/
|
||||||
unstageInstall(stagedAddon) {
|
async unstageInstall(stagedAddon) {
|
||||||
return Task.spawn((function*() {
|
let stagedJSON = getFile(`${this.addon.id}.json`, stagedAddon);
|
||||||
let stagedJSON = stagedAddon.clone();
|
if (stagedJSON.exists()) {
|
||||||
let removedAddon = stagedAddon.clone();
|
stagedJSON.remove(true);
|
||||||
|
}
|
||||||
|
|
||||||
stagedJSON.append(this.addon.id + ".json");
|
await removeAsync(getFile(this.addon.id, stagedAddon));
|
||||||
|
|
||||||
if (stagedJSON.exists()) {
|
await removeAsync(getFile(`${this.addon.id}.xpi`, stagedAddon));
|
||||||
stagedJSON.remove(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
removedAddon.append(this.addon.id);
|
|
||||||
yield removeAsync(removedAddon);
|
|
||||||
removedAddon.leafName = this.addon.id + ".xpi";
|
|
||||||
yield removeAsync(removedAddon);
|
|
||||||
}).bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6371,49 +6353,45 @@ class AddonInstall {
|
||||||
* @param {Function} resumeFn - a function for the add-on to run
|
* @param {Function} resumeFn - a function for the add-on to run
|
||||||
* when resuming.
|
* when resuming.
|
||||||
*/
|
*/
|
||||||
postpone(resumeFn) {
|
async postpone(resumeFn) {
|
||||||
return Task.spawn((function*() {
|
this.state = AddonManager.STATE_POSTPONED;
|
||||||
this.state = AddonManager.STATE_POSTPONED;
|
|
||||||
|
|
||||||
let stagingDir = this.installLocation.getStagingDir();
|
let stagingDir = this.installLocation.getStagingDir();
|
||||||
let stagedAddon = stagingDir.clone();
|
|
||||||
|
|
||||||
yield this.installLocation.requestStagingDir();
|
await this.installLocation.requestStagingDir();
|
||||||
yield this.unstageInstall(stagedAddon);
|
await this.unstageInstall(stagingDir);
|
||||||
|
|
||||||
stagedAddon.append(this.addon.id);
|
let stagedAddon = getFile(`${this.addon.id}.xpi`, stagingDir);
|
||||||
stagedAddon.leafName = this.addon.id + ".xpi";
|
|
||||||
|
|
||||||
yield this.stageInstall(true, stagedAddon, true);
|
await this.stageInstall(true, stagedAddon, true);
|
||||||
|
|
||||||
AddonManagerPrivate.callInstallListeners("onInstallPostponed",
|
AddonManagerPrivate.callInstallListeners("onInstallPostponed",
|
||||||
this.listeners, this.wrapper)
|
this.listeners, this.wrapper)
|
||||||
|
|
||||||
// upgrade has been staged for restart, provide a way for it to call the
|
// upgrade has been staged for restart, provide a way for it to call the
|
||||||
// resume function.
|
// resume function.
|
||||||
let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id);
|
let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback({
|
||||||
version: this.version,
|
version: this.version,
|
||||||
install: () => {
|
install: () => {
|
||||||
switch (this.state) {
|
switch (this.state) {
|
||||||
case AddonManager.STATE_POSTPONED:
|
case AddonManager.STATE_POSTPONED:
|
||||||
if (resumeFn) {
|
if (resumeFn) {
|
||||||
resumeFn();
|
resumeFn();
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
},
|
break;
|
||||||
});
|
default:
|
||||||
}
|
logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`);
|
||||||
// Release the staging directory lock, but since the staging dir is populated
|
break;
|
||||||
// it will not be removed until resumed or installed by restart.
|
}
|
||||||
// See also cleanStagingDir()
|
},
|
||||||
this.installLocation.releaseStagingDir();
|
});
|
||||||
}).bind(this));
|
}
|
||||||
|
// Release the staging directory lock, but since the staging dir is populated
|
||||||
|
// it will not be removed until resumed or installed by restart.
|
||||||
|
// See also cleanStagingDir()
|
||||||
|
this.installLocation.releaseStagingDir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8576,9 +8554,7 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
* @return an nsIFile
|
* @return an nsIFile
|
||||||
*/
|
*/
|
||||||
getStagingDir() {
|
getStagingDir() {
|
||||||
let dir = this._directory.clone();
|
return getFile(DIR_STAGE, this._directory);
|
||||||
dir.append(DIR_STAGE);
|
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestStagingDir() {
|
requestStagingDir() {
|
||||||
|
@ -8620,8 +8596,7 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
let dir = this.getStagingDir();
|
let dir = this.getStagingDir();
|
||||||
|
|
||||||
for (let name of aLeafNames) {
|
for (let name of aLeafNames) {
|
||||||
let file = dir.clone();
|
let file = getFile(name, dir);
|
||||||
file.append(name);
|
|
||||||
recursiveRemove(file);
|
recursiveRemove(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8654,8 +8629,7 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
* @return an nsIFile
|
* @return an nsIFile
|
||||||
*/
|
*/
|
||||||
getTrashDir() {
|
getTrashDir() {
|
||||||
let trashDir = this._directory.clone();
|
let trashDir = getFile(DIR_TRASH, this._directory);
|
||||||
trashDir.append(DIR_TRASH);
|
|
||||||
let trashDirExists = trashDir.exists();
|
let trashDirExists = trashDir.exists();
|
||||||
try {
|
try {
|
||||||
if (trashDirExists)
|
if (trashDirExists)
|
||||||
|
@ -8696,14 +8670,11 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
let transaction = new SafeInstallOperation();
|
let transaction = new SafeInstallOperation();
|
||||||
|
|
||||||
let moveOldAddon = aId => {
|
let moveOldAddon = aId => {
|
||||||
let file = this._directory.clone();
|
let file = getFile(aId, this._directory);
|
||||||
file.append(aId);
|
|
||||||
|
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
transaction.moveUnder(file, trashDir);
|
transaction.moveUnder(file, trashDir);
|
||||||
|
|
||||||
file = this._directory.clone();
|
file = getFile(`${aId}.xpi`, this._directory);
|
||||||
file.append(aId + ".xpi");
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
flushJarCache(file);
|
flushJarCache(file);
|
||||||
transaction.moveUnder(file, trashDir);
|
transaction.moveUnder(file, trashDir);
|
||||||
|
@ -8732,8 +8703,7 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
KEY_PROFILEDIR, ["extension-data", id], false, true
|
KEY_PROFILEDIR, ["extension-data", id], false, true
|
||||||
);
|
);
|
||||||
if (newDataDir.exists()) {
|
if (newDataDir.exists()) {
|
||||||
let trashData = trashDir.clone();
|
let trashData = getFile("data-directory", trashDir);
|
||||||
trashData.append("data-directory");
|
|
||||||
transaction.moveUnder(newDataDir, trashData);
|
transaction.moveUnder(newDataDir, trashData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8804,8 +8774,7 @@ class MutableDirectoryInstallLocation extends DirectoryInstallLocation {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = this._directory.clone();
|
file = getFile(aId, this._directory);
|
||||||
file.append(aId);
|
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
file.leafName += ".xpi";
|
file.leafName += ".xpi";
|
||||||
|
|
||||||
|
@ -8869,8 +8838,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
|
||||||
// Therefore, this is looked up before calling the
|
// Therefore, this is looked up before calling the
|
||||||
// constructor on the superclass.
|
// constructor on the superclass.
|
||||||
if (addonSet.directory) {
|
if (addonSet.directory) {
|
||||||
directory = aDirectory.clone();
|
directory = getFile(addonSet.directory, aDirectory);
|
||||||
directory.append(addonSet.directory);
|
|
||||||
logger.info("SystemAddonInstallLocation scanning directory " + directory.path);
|
logger.info("SystemAddonInstallLocation scanning directory " + directory.path);
|
||||||
} else {
|
} else {
|
||||||
logger.info("SystemAddonInstallLocation directory is missing");
|
logger.info("SystemAddonInstallLocation directory is missing");
|
||||||
|
@ -8902,10 +8870,8 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
|
||||||
this._addonSet = SystemAddonInstallLocation._loadAddonSet();
|
this._addonSet = SystemAddonInstallLocation._loadAddonSet();
|
||||||
let dir = null;
|
let dir = null;
|
||||||
if (this._addonSet.directory) {
|
if (this._addonSet.directory) {
|
||||||
this._directory = this._baseDir.clone();
|
this._directory = getFile(this._addonSet.directory, this._baseDir);
|
||||||
this._directory.append(this._addonSet.directory);
|
dir = getFile(DIR_STAGE, this._directory);
|
||||||
dir = this._directory.clone();
|
|
||||||
dir.append(DIR_STAGE);
|
|
||||||
} else {
|
} else {
|
||||||
logger.info("SystemAddonInstallLocation directory is missing");
|
logger.info("SystemAddonInstallLocation directory is missing");
|
||||||
}
|
}
|
||||||
|
@ -8916,8 +8882,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
|
||||||
requestStagingDir() {
|
requestStagingDir() {
|
||||||
this._addonSet = SystemAddonInstallLocation._loadAddonSet();
|
this._addonSet = SystemAddonInstallLocation._loadAddonSet();
|
||||||
if (this._addonSet.directory) {
|
if (this._addonSet.directory) {
|
||||||
this._directory = this._baseDir.clone();
|
this._directory = getFile(this._addonSet.directory, this._baseDir);
|
||||||
this._directory.append(this._addonSet.directory);
|
|
||||||
}
|
}
|
||||||
return super.requestStagingDir();
|
return super.requestStagingDir();
|
||||||
}
|
}
|
||||||
|
@ -9243,8 +9208,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
|
||||||
* @return an nsIFile
|
* @return an nsIFile
|
||||||
*/
|
*/
|
||||||
getTrashDir() {
|
getTrashDir() {
|
||||||
let trashDir = this._directory.clone();
|
let trashDir = getFile(DIR_TRASH, this._directory);
|
||||||
trashDir.append(DIR_TRASH);
|
|
||||||
let trashDirExists = trashDir.exists();
|
let trashDirExists = trashDir.exists();
|
||||||
try {
|
try {
|
||||||
if (trashDirExists)
|
if (trashDirExists)
|
||||||
|
@ -9290,8 +9254,7 @@ class SystemAddonInstallLocation extends MutableDirectoryInstallLocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let newFile = this._directory.clone();
|
let newFile = getFile(source.leafName, this._directory);
|
||||||
newFile.append(source.leafName);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newFile.lastModifiedTime = Date.now();
|
newFile.lastModifiedTime = Date.now();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче