Skip to content

Commit a274f91

Browse files
author
Kirk Steuber
committed
Bug 1732435 - r=nalexander,application-update-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D127894
1 parent 4c371ab commit a274f91

File tree

9 files changed

+122
-1754
lines changed

9 files changed

+122
-1754
lines changed

toolkit/components/maintenanceservice/workmonitor.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -801,25 +801,6 @@ BOOL ExecuteServiceCommand(int argc, LPWSTR* argv) {
801801
// because the service self updates itself and the service
802802
// installer will stop the service.
803803
LOG(("Service command %ls complete.", argv[2]));
804-
} else if (!lstrcmpi(argv[2], L"fix-update-directory-perms")) {
805-
bool gotInstallDir = true;
806-
mozilla::UniquePtr<wchar_t[]> updateDir;
807-
if (argc <= 3) {
808-
LOG_WARN(("Didn't get an install dir for fix-update-directory-perms"));
809-
gotInstallDir = false;
810-
}
811-
HRESULT permResult =
812-
GetCommonUpdateDirectory(gotInstallDir ? argv[3] : nullptr,
813-
SetPermissionsOf::AllFilesAndDirs, updateDir);
814-
if (FAILED(permResult)) {
815-
LOG_WARN(
816-
("Unable to set the permissions on the update directory "
817-
"('%S'): %d",
818-
updateDir.get(), permResult));
819-
result = FALSE;
820-
} else {
821-
result = TRUE;
822-
}
823804
} else {
824805
LOG_WARN(("Service command not recognized: %ls.", argv[2]));
825806
// result is already set to FALSE

toolkit/mozapps/update/UpdateService.jsm

Lines changed: 4 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,7 @@ const ONLY_INSTANCE_CHECK_DEFAULT_TIMEOUT_MS = 6 * 60 * 60 * 1000; // 6 hours
301301
// that value to this so that the pref can't effectively disable the feature.
302302
const ONLY_INSTANCE_CHECK_MAX_TIMEOUT_MS = 2 * 24 * 60 * 60 * 1000; // 2 days
303303

304-
// Object to keep track of the current phase of the update and whether there
305-
// has been a write failure for the phase so only one telemetry ping is made
306-
// for the phase.
307-
var gUpdateFileWriteInfo = { phase: null, failure: false };
308304
var gUpdateMutexHandle = null;
309-
// The permissions of the update directory should be fixed no more than once per
310-
// session
311-
var gUpdateDirPermissionFixAttempted = false;
312305
// This is the file stream used for the log file.
313306
var gLogfileOutputStream;
314307
// This value will be set to true if it appears that BITS is being used by
@@ -745,10 +738,6 @@ function getCanApplyUpdates() {
745738
"access to the update directory. Exception: " +
746739
e
747740
);
748-
// Attempt to fix the update directory permissions. If successful the next
749-
// time this function is called the write access check to the update
750-
// directory will succeed.
751-
fixUpdateDirectoryPermissions();
752741
return false;
753742
}
754743

@@ -1171,10 +1160,7 @@ function readBinaryTransparencyResult(dir) {
11711160
function writeStatusFile(dir, state) {
11721161
let statusFile = dir.clone();
11731162
statusFile.append(FILE_UPDATE_STATUS);
1174-
let success = writeStringToFile(statusFile, state);
1175-
if (!success) {
1176-
handleCriticalWriteFailure(statusFile.path);
1177-
}
1163+
writeStringToFile(statusFile, state);
11781164
}
11791165

11801166
/**
@@ -1195,10 +1181,7 @@ function writeStatusFile(dir, state) {
11951181
function writeVersionFile(dir, version) {
11961182
let versionFile = dir.clone();
11971183
versionFile.append(FILE_UPDATE_VERSION);
1198-
let success = writeStringToFile(versionFile, version);
1199-
if (!success) {
1200-
handleCriticalWriteFailure(versionFile.path);
1201-
}
1184+
writeStringToFile(versionFile, version);
12021185
}
12031186

12041187
/**
@@ -1811,122 +1794,6 @@ function pingStateAndStatusCodes(aUpdate, aStartup, aStatus) {
18111794
AUSTLMY.pingStateCode(suffix, stateCode);
18121795
}
18131796

1814-
/**
1815-
* Asynchronously fixes the update directory permissions. This is currently only
1816-
* available on Windows.
1817-
*
1818-
* @return true if the permission-fixing process was started, and false if the
1819-
* permission-fixing process was not started or the platform is not
1820-
* supported.
1821-
*/
1822-
function fixUpdateDirectoryPermissions() {
1823-
if (AppConstants.platform != "win") {
1824-
LOG(
1825-
"There is currently no implementation for fixing update directory " +
1826-
"permissions on this platform"
1827-
);
1828-
return false;
1829-
}
1830-
1831-
if (!gUpdateDirPermissionFixAttempted) {
1832-
// Never try to fix permissions more than one time during a session.
1833-
gUpdateDirPermissionFixAttempted = true;
1834-
1835-
LOG("Attempting to fix update directory permissions");
1836-
try {
1837-
Cc["@mozilla.org/updates/update-processor;1"]
1838-
.createInstance(Ci.nsIUpdateProcessor)
1839-
.fixUpdateDirectoryPerms(shouldUseService());
1840-
} catch (e) {
1841-
LOG(
1842-
"Attempt to fix update directory permissions failed. Exception: " + e
1843-
);
1844-
return false;
1845-
}
1846-
return true;
1847-
}
1848-
return false;
1849-
}
1850-
1851-
/**
1852-
* This function should be called whenever we fail to write to a file required
1853-
* for update to function. This function will, if possible, attempt to fix the
1854-
* file permissions. If the file permissions cannot be fixed, the user will be
1855-
* prompted to reinstall.
1856-
*
1857-
* All functionality happens asynchronously.
1858-
*
1859-
* Returns false if the permission-fixing process cannot be started. Since this
1860-
* is asynchronous, a true return value does not mean that the permissions were
1861-
* actually fixed.
1862-
*
1863-
* @param path A string representing the path that could not be written. This
1864-
* value will only be used for logging purposes.
1865-
*/
1866-
function handleCriticalWriteFailure(path) {
1867-
LOG(
1868-
"handleCriticalWriteFailure - Unable to write to critical update file: " +
1869-
path
1870-
);
1871-
if (!gUpdateFileWriteInfo.failure) {
1872-
gUpdateFileWriteInfo.failure = true;
1873-
let patchType = AUSTLMY.PATCH_UNKNOWN;
1874-
let update = UM.readyUpdate || UM.downloadingUpdate;
1875-
if (update) {
1876-
let patch = update.selectedPatch;
1877-
if (patch.type == "complete") {
1878-
patchType = AUSTLMY.PATCH_COMPLETE;
1879-
} else if (patch.type == "partial") {
1880-
patchType = AUSTLMY.PATCH_PARTIAL;
1881-
}
1882-
}
1883-
1884-
if (gUpdateFileWriteInfo.phase == "check") {
1885-
let updateServiceInstance = UpdateServiceFactory.createInstance();
1886-
let pingSuffix = updateServiceInstance._pingSuffix;
1887-
if (!pingSuffix) {
1888-
// If pingSuffix isn't defined then this this is a manual check which
1889-
// isn't recorded at this time.
1890-
AUSTLMY.pingCheckCode(pingSuffix, AUSTLMY.CHK_ERR_WRITE_FAILURE);
1891-
}
1892-
} else if (gUpdateFileWriteInfo.phase == "download") {
1893-
AUSTLMY.pingDownloadCode(patchType, AUSTLMY.DWNLD_ERR_WRITE_FAILURE);
1894-
} else if (gUpdateFileWriteInfo.phase == "stage") {
1895-
let suffix = patchType + "_" + AUSTLMY.STAGE;
1896-
AUSTLMY.pingStateCode(suffix, AUSTLMY.STATE_WRITE_FAILURE);
1897-
} else if (gUpdateFileWriteInfo.phase == "startup") {
1898-
let suffix = patchType + "_" + AUSTLMY.STARTUP;
1899-
AUSTLMY.pingStateCode(suffix, AUSTLMY.STATE_WRITE_FAILURE);
1900-
} else {
1901-
// Temporary failure code to see if there are failures without an update
1902-
// phase.
1903-
AUSTLMY.pingDownloadCode(
1904-
patchType,
1905-
AUSTLMY.DWNLD_UNKNOWN_PHASE_ERR_WRITE_FAILURE
1906-
);
1907-
}
1908-
}
1909-
1910-
return fixUpdateDirectoryPermissions();
1911-
}
1912-
1913-
/**
1914-
* This is a convenience function for calling the above function depending on a
1915-
* boolean success value.
1916-
*
1917-
* @param wroteSuccessfully A boolean representing whether or not the write was
1918-
* successful. When this is true, this function does
1919-
* nothing.
1920-
* @param path A string representing the path to the file that the operation
1921-
* attempted to write to. This value is only used for logging
1922-
* purposes.
1923-
*/
1924-
function handleCriticalWriteResult(wroteSuccessfully, path) {
1925-
if (!wroteSuccessfully) {
1926-
handleCriticalWriteFailure(path);
1927-
}
1928-
}
1929-
19301797
/**
19311798
* This returns true if the passed update is the same version or older than the
19321799
* version and build ID values passed. Otherwise it returns false.
@@ -2741,7 +2608,6 @@ UpdateService.prototype = {
27412608
// update is broken and they should reinstall.
27422609
return;
27432610
}
2744-
gUpdateFileWriteInfo = { phase: "startup", failure: false };
27452611
if (!this.canCheckForUpdates) {
27462612
LOG(
27472613
"UpdateService:_postUpdateProcessing - unable to check for " +
@@ -4239,7 +4105,6 @@ UpdateManager.prototype = {
42394105
"stream. Exception: " +
42404106
e
42414107
);
4242-
fixUpdateDirectoryPermissions();
42434108
return updates;
42444109
}
42454110
try {
@@ -4475,12 +4340,7 @@ UpdateManager.prototype = {
44754340
// the lifetime of an active update and the file should always be updated
44764341
// when saveUpdates is called.
44774342
let promises = [];
4478-
promises[0] = this._writeUpdatesToXMLFile(
4479-
updates,
4480-
FILE_ACTIVE_UPDATE_XML
4481-
).then(wroteSuccessfully =>
4482-
handleCriticalWriteResult(wroteSuccessfully, FILE_ACTIVE_UPDATE_XML)
4483-
);
4343+
promises[0] = this._writeUpdatesToXMLFile(updates, FILE_ACTIVE_UPDATE_XML);
44844344
// The update history stored in the updates.xml file should only need to be
44854345
// updated when an active update has been added to it in which case
44864346
// |_updatesDirty| will be true.
@@ -4489,8 +4349,6 @@ UpdateManager.prototype = {
44894349
promises[1] = this._writeUpdatesToXMLFile(
44904350
this._getUpdates(),
44914351
FILE_UPDATES_XML
4492-
).then(wroteSuccessfully =>
4493-
handleCriticalWriteResult(wroteSuccessfully, FILE_UPDATES_XML)
44944352
);
44954353
}
44964354
return Promise.all(promises);
@@ -4725,7 +4583,6 @@ Checker.prototype = {
47254583
*/
47264584
checkForUpdates: function UC_checkForUpdates(listener, force) {
47274585
LOG("Checker: checkForUpdates, force: " + force);
4728-
gUpdateFileWriteInfo = { phase: "check", failure: false };
47294586
if (!listener) {
47304587
throw Components.Exception("", Cr.NS_ERROR_NULL_POINTER);
47314588
}
@@ -5378,7 +5235,6 @@ Downloader.prototype = {
53785235
*/
53795236
downloadUpdate: function Downloader_downloadUpdate(update) {
53805237
LOG("UpdateService:_downloadUpdate");
5381-
gUpdateFileWriteInfo = { phase: "download", failure: false };
53825238
if (!update) {
53835239
AUSTLMY.pingDownloadCode(undefined, AUSTLMY.DWNLD_ERR_NO_UPDATE);
53845240
throw Components.Exception("", Cr.NS_ERROR_NULL_POINTER);
@@ -5880,7 +5736,6 @@ Downloader.prototype = {
58805736
);
58815737
// Prevent the preference from setting a value greater than 20.
58825738
maxFail = Math.min(maxFail, 20);
5883-
let permissionFixingInProgress = false;
58845739
LOG(
58855740
"Downloader:onStopRequest - status: " +
58865741
status +
@@ -5946,12 +5801,6 @@ Downloader.prototype = {
59465801
deleteActiveUpdate = true;
59475802

59485803
cleanUpDownloadingUpdateDir();
5949-
5950-
let failedWrite = readyDir.clone();
5951-
failedWrite.append(FILE_UPDATE_MAR);
5952-
permissionFixingInProgress = handleCriticalWriteFailure(
5953-
failedWrite.path
5954-
);
59555804
}
59565805
} else {
59575806
LOG("Downloader:onStopRequest - download verification failed");
@@ -6013,11 +5862,6 @@ Downloader.prototype = {
60135862
status == Cr.NS_ERROR_FILE_READ_ONLY
60145863
) {
60155864
LOG("Downloader:onStopRequest - permission error");
6016-
// This will either fix the permissions, or asynchronously show the
6017-
// reinstall prompt if it cannot fix them.
6018-
let patchFile = getDownloadingUpdateDir();
6019-
patchFile.append(FILE_UPDATE_MAR);
6020-
permissionFixingInProgress = handleCriticalWriteFailure(patchFile.path);
60215865
nonDownloadFailure = true;
60225866
} else {
60235867
LOG("Downloader:onStopRequest - non-verification failure");
@@ -6154,7 +5998,7 @@ Downloader.prototype = {
61545998
}
61555999
}
61566000

6157-
if (allFailed && !permissionFixingInProgress) {
6001+
if (allFailed) {
61586002
let downloadAttempts = Services.prefs.getIntPref(
61596003
PREF_APP_UPDATE_DOWNLOAD_ATTEMPTS,
61606004
0
@@ -6231,7 +6075,6 @@ Downloader.prototype = {
62316075
"Downloader:onStopRequest - attempting to stage update: " +
62326076
this._update.name
62336077
);
6234-
gUpdateFileWriteInfo = { phase: "stage", failure: false };
62356078
// Stage the update
62366079
try {
62376080
Cc["@mozilla.org/updates/update-processor;1"]

0 commit comments

Comments
 (0)