Bug 757965 - Properly test for write access before staging an update in the background; r=rstrong

This patch makes sure that we test to make sure we can create a
directory in the installation directory and also in its parent (the
latter check only happens on Windows and Linux), so that we wouldn't try
to stage an update in the background if that's bound to fail if we don't
have the require write permissions.
This commit is contained in:
Ehsan Akhgari 2012-05-30 17:57:05 -04:00
Родитель 46da43c007
Коммит 6765e2ec2c
1 изменённых файлов: 19 добавлений и 3 удалений

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

@ -432,15 +432,15 @@ XPCOMUtils.defineLazyGetter(this, "gCanStageUpdates", function aus_gCanStageUpda
#endif
try {
var updateTestFile = getUpdateFile([FILE_PERMS_TEST]);
var updateTestFile = getInstallDirRoot();
updateTestFile.append(FILE_PERMS_TEST);
LOG("gCanStageUpdates - testing write access " + updateTestFile.path);
testWriteAccess(updateTestFile, true);
#ifndef XP_MACOSX
// On all platforms except Mac, we need to test the parent directory as well,
// as we need to be able to move files in that directory during the replacing
// step.
updateTestFile = getUpdateDirCreate([]);
updateTestFile = updateTestFile.parent;
updateTestFile = getInstallDirRoot().parent;
updateTestFile.append(FILE_PERMS_TEST);
LOG("gCanStageUpdates - testing write access " + updateTestFile.path);
updateTestFile.createUnique(Ci.nsILocalFile.DIRECTORY_TYPE,
@ -552,6 +552,22 @@ function getUpdateDirCreate(pathArray) {
return FileUtils.getDir(KEY_APPDIR, pathArray, true);
}
/**
* Gets the root of the installation directory which is the application
* bundle directory on Mac OS X and the location of the application binary
* on all other platforms.
*
* @return nsIFile object for the directory
*/
function getInstallDirRoot() {
var dir = FileUtils.getDir(KEY_APPDIR, [], false);
#ifdef XP_MACOSX
// On Mac, we store the Updated.app directory inside the bundle directory.
dir = dir.parent.parent;
#endif
return dir;
}
/**
* Gets the file at the specified hierarchy under the update root directory.
* @param pathArray