Bug 793767 - Use the executable file location to derive the update root. r=rstrong

This commit is contained in:
Mike Hommey 2013-02-08 15:58:52 +01:00
parent d93b5e831a
commit a2baccb09c
7 changed files with 69 additions and 87 deletions

View File

@ -412,10 +412,9 @@ function writeUpdatesToXMLFile(aText)
const MODE_CREATE = 0x08;
const MODE_TRUNCATE = 0x20;
const kIsWin = (navigator.platform.indexOf("Win") == 0);
let file = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get(kIsWin ? "UpdRootD" : "XCurProcD", Ci.nsIFile);
get("UpdRootD", Ci.nsIFile);
file.append("updates.xml");
let fos = Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);

View File

@ -2101,9 +2101,7 @@ XPCShellDirProvider::GetFile(const char *prop, bool *persistent,
#endif
return localFile->Clone(result);
#else
// Fail on non-Windows platforms, the caller is supposed to fal back on
// the app dir.
return NS_ERROR_FAILURE;
return mAppFile->GetParent(result);
#endif
}

View File

@ -65,23 +65,14 @@ const URI_UPDATE_NS = "http://www.mozilla.org/2005/app-update";
const CATEGORY_UPDATE_TIMER = "update-timer";
const KEY_APPDIR = "XCurProcD";
const KEY_GRED = "GreD";
#ifdef XP_WIN
#define USE_UPDROOT
#elifdef ANDROID
#define USE_UPDROOT
#endif
const KEY_UPDROOT = "UpdRootD";
const KEY_EXECUTABLE = "XREExeF";
#ifdef MOZ_WIDGET_GONK
#define USE_UPDATE_ARCHIVE_DIR
#endif
#ifdef USE_UPDROOT
const KEY_UPDROOT = "UpdRootD";
#endif
#ifdef USE_UPDATE_ARCHIVE_DIR
const KEY_UPDATE_ARCHIVE_DIR = "UpdArchD"
#endif
@ -470,7 +461,8 @@ XPCOMUtils.defineLazyGetter(this, "gCanApplyUpdates", function aus_gCanApplyUpda
*/
if (!userCanElevate) {
// if we're unable to create the test file this will throw an exception.
var appDirTestFile = FileUtils.getFile(KEY_APPDIR, [FILE_PERMS_TEST]);
var appDirTestFile = getAppBaseDir();
appDirTestFile.append(FILE_PERMS_TEST);
LOG("gCanApplyUpdates - testing write access " + appDirTestFile.path);
if (appDirTestFile.exists())
appDirTestFile.remove(false)
@ -618,14 +610,27 @@ function binaryToHex(input) {
# @return nsIFile object for the location specified.
*/
function getUpdateDirCreate(pathArray) {
#ifdef USE_UPDROOT
try {
let dir = FileUtils.getDir(KEY_UPDROOT, pathArray, true);
return dir;
} catch (e) {
}
#endif
return FileUtils.getDir(KEY_APPDIR, pathArray, true);
return FileUtils.getDir(KEY_UPDROOT, pathArray, true);
}
/**
# Gets the specified directory at the specified hierarchy under the
# update root directory and without creating it if it doesn't exist.
# @param pathArray
# An array of path components to locate beneath the directory
# specified by |key|
# @return nsIFile object for the location specified.
*/
function getUpdateDirNoCreate(pathArray) {
return FileUtils.getDir(KEY_UPDROOT, pathArray, false);
}
/**
# Gets the application base directory.
# @return nsIFile object for the application base directory.
*/
function getAppBaseDir() {
return Services.dirsvc.get(KEY_EXECUTABLE, Ci.nsIFile).parent;
}
/**
@ -636,7 +641,7 @@ function getUpdateDirCreate(pathArray) {
* @return nsIFile object for the directory
*/
function getInstallDirRoot() {
var dir = FileUtils.getDir(KEY_APPDIR, [], false);
var dir = getAppBaseDir();
#ifdef XP_MACOSX
// On Mac, we store the Updated.app directory inside the bundle directory.
dir = dir.parent.parent;
@ -696,7 +701,6 @@ function getUpdatesDir() {
return getUpdateDirCreate([DIR_UPDATES, "0"]);
}
#ifndef USE_UPDROOT
/**
* Get the Active Updates directory inside the directory where we apply the
* background updates.
@ -704,7 +708,7 @@ function getUpdatesDir() {
* nsIFile object.
*/
function getUpdatesDirInApplyToDir() {
var dir = FileUtils.getDir(KEY_APPDIR, []);
var dir = getAppBaseDir();
#ifdef XP_MACOSX
dir = dir.parent.parent; // the bundle directory
#endif
@ -719,7 +723,6 @@ function getUpdatesDirInApplyToDir() {
}
return dir;
}
#endif
/**
* Reads the update state from the update.status file in the specified
@ -951,26 +954,16 @@ function cleanUpUpdatesDir(aBackgroundUpdate) {
if (f.leafName == FILE_UPDATE_LOG) {
var dir;
try {
#ifdef USE_UPDROOT
// If we're on a platform which uses the update root directory, the log
// files are written outside of the application directory, so they will
// not get overwritten when we replace the directories after a
// background update. Therefore, we don't need any special logic for
// that case here.
// Note that this currently only applies to Windows.
dir = f.parent.parent;
#else
// If we don't use the update root directory, the log files are written
// inside the application directory. In that case, we want to write
// the log files to the updated directory in the case of background
// updates, so that they would be available when we replace that
// directory with the application directory later on.
if (aBackgroundUpdate) {
if (aBackgroundUpdate && getUpdateDirNoCreate([]).equals(getAppBaseDir())) {
dir = getUpdatesDirInApplyToDir();
} else {
dir = f.parent.parent;
}
#endif
var logFile = dir.clone();
logFile.append(FILE_LAST_LOG);
if (logFile.exists()) {
@ -1059,8 +1052,8 @@ function getLocale() {
if (!gLocale)
throw Components.Exception(FILE_UPDATE_LOCALE + " file doesn't exist in " +
"either the " + KEY_APPDIR + " or " + KEY_GRED +
" directories", Cr.NS_ERROR_FILE_NOT_FOUND);
"either the application or GRE directories",
Cr.NS_ERROR_FILE_NOT_FOUND);
LOG("getLocale - getting locale from file: " + channel.originalURI.spec +
", locale: " + gLocale);

View File

@ -12,17 +12,7 @@ const Ci = Components.interfaces;
const DIR_UPDATES = "updates";
const FILE_UPDATE_STATUS = "update.status";
const KEY_APPDIR = "XCurProcD";
#ifdef XP_WIN
#define USE_UPDROOT
#elifdef ANDROID
#define USE_UPDROOT
#endif
#ifdef USE_UPDROOT
const KEY_UPDROOT = "UpdRootD";
#endif
/**
# Gets the specified directory at the specified hierarchy under the update root
@ -33,14 +23,7 @@ const KEY_UPDROOT = "UpdRootD";
# @return nsIFile object for the location specified.
*/
function getUpdateDirNoCreate(pathArray) {
#ifdef USE_UPDROOT
try {
let dir = FileUtils.getDir(KEY_UPDROOT, pathArray, false);
return dir;
} catch (e) {
}
#endif
return FileUtils.getDir(KEY_APPDIR, pathArray, false);
return FileUtils.getDir(KEY_UPDROOT, pathArray, false);
}
function UpdateServiceStub() {

View File

@ -3451,8 +3451,14 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
if (CheckArg("process-updates")) {
SaveToEnv("MOZ_PROCESS_UPDATES=1");
}
nsCOMPtr<nsIFile> exeFile, exeDir;
rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
getter_AddRefs(exeFile));
NS_ENSURE_SUCCESS(rv, 1);
rv = exeFile->GetParent(getter_AddRefs(exeDir));
NS_ENSURE_SUCCESS(rv, 1);
ProcessUpdates(mDirProvider.GetGREDir(),
mDirProvider.GetAppDir(),
exeDir,
updRoot,
gRestartArgc,
gRestartArgv,

View File

@ -1036,7 +1036,15 @@ nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate)
updRoot = dirProvider->GetAppDir();
greDir = dirProvider->GetGREDir();
appDir = dirProvider->GetAppDir();
nsCOMPtr<nsIFile> exeFile;
rv = dirProvider->GetFile(XRE_EXECUTABLE_FILE, &persistent,
getter_AddRefs(exeFile));
if (NS_SUCCEEDED(rv))
rv = exeFile->GetParent(getter_AddRefs(appDir));
if (NS_FAILED(rv))
appDir = dirProvider->GetAppDir();
appVersion = gAppData->version;
argc = gRestartArgc;
argv = gRestartArgv;

View File

@ -307,12 +307,7 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
rv = GetUserAppDataDirectory(getter_AddRefs(file));
}
else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
#if defined(XP_WIN) || defined(MOZ_WIDGET_GONK)
rv = GetUpdateRootDir(getter_AddRefs(file));
#else
// Only supported on Windows, so just immediately fail.
return NS_ERROR_FAILURE;
#endif
}
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
rv = GetUserAppDataDirectory(getter_AddRefs(file));
@ -946,14 +941,30 @@ GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
return NS_OK;
}
#endif
nsresult
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
{
nsCOMPtr<nsIFile> appDir = GetAppDir();
nsCOMPtr<nsIFile> updRoot;
#if defined(MOZ_WIDGET_GONK)
nsresult rv = NS_NewNativeLocalFile(nsDependentCString("/data/local"),
true,
getter_AddRefs(updRoot));
NS_ENSURE_SUCCESS(rv, rv);
#else
nsCOMPtr<nsIFile> appFile;
bool per = false;
nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = appFile->GetParent(getter_AddRefs(updRoot));
NS_ENSURE_SUCCESS(rv, rv);
#ifdef XP_WIN
nsAutoString appPath;
nsresult rv = appDir->GetPath(appPath);
rv = updRoot->GetPath(appPath);
NS_ENSURE_SUCCESS(rv, rv);
// AppDir may be a short path. Convert to long path to make sure
@ -996,33 +1007,17 @@ nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
programName.AssignASCII(MOZ_APP_NAME);
}
nsCOMPtr<nsIFile> updRoot;
rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
NS_ENSURE_SUCCESS(rv, rv);
rv = updRoot->AppendRelativePath(programName);
NS_ENSURE_SUCCESS(rv, rv);
#endif
#endif
NS_ADDREF(*aResult = updRoot);
return NS_OK;
}
#endif
#if defined(MOZ_WIDGET_GONK)
nsresult
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
{
nsCOMPtr<nsIFile> updRoot;
nsresult rv = NS_NewNativeLocalFile(nsDependentCString("/data/local"),
true,
getter_AddRefs(updRoot));
NS_ENSURE_SUCCESS(rv, rv);
NS_IF_ADDREF(*aResult = updRoot);
return NS_OK;
}
#endif
nsresult
nsXREDirProvider::GetProfileStartupDir(nsIFile* *aResult)