Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: abort ShipIt installation attempt at the final mile if the app i…
…s running (#36362) fix: abort ShipIt installation attempt at the final mile if the app is running (#36130) * fix: abort ShipIt installation attempt at the final mile if the app is running * chore: remove only * Update patches/squirrel.mac/fix_abort_installation_attempt_at_the_final_mile_if_the_app_is.patch Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: update patches * spec: make the ShipIt process lister helper more resilient Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
- Loading branch information
1 parent
39f23b0
commit 5d418c5
Showing
6 changed files
with
191 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
patches/squirrel.mac/fix_abort_installation_attempt_at_the_final_mile_if_the_app_is.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Samuel Attard <sattard@salesforce.com> | ||
Date: Tue, 25 Oct 2022 13:09:55 -0700 | ||
Subject: fix: abort installation attempt at the final mile if the app is | ||
running | ||
|
||
There is a race condition between ShipIt launching and it performing an atomic rename to "install" the app bundle. This fixes the race by checking the list of running apps immediately before performing the rename. | ||
|
||
diff --git a/Squirrel/SQRLInstaller.h b/Squirrel/SQRLInstaller.h | ||
index 2de1c384aae200f41de429cc35313e4c2ba9d0de..35a0c99129478f09526667d73c9544c3bfe14706 100644 | ||
--- a/Squirrel/SQRLInstaller.h | ||
+++ b/Squirrel/SQRLInstaller.h | ||
@@ -37,6 +37,9 @@ extern const NSInteger SQRLInstallerErrorMovingAcrossVolumes; | ||
// There was an error changing the file permissions of the update. | ||
extern const NSInteger SQRLInstallerErrorChangingPermissions; | ||
|
||
+// There was a running instance of the app just prior to the update attempt | ||
+extern const NSInteger SQRLInstallerErrorAppStillRunning; | ||
+ | ||
@class RACCommand; | ||
|
||
// Performs the installation of an update, saving its intermediate state to user | ||
diff --git a/Squirrel/SQRLInstaller.m b/Squirrel/SQRLInstaller.m | ||
index c1f328fa8c3689218ef260347cb8f9d30b789efe..f502df2f88424ea902a061adfeb30358daf212e4 100644 | ||
--- a/Squirrel/SQRLInstaller.m | ||
+++ b/Squirrel/SQRLInstaller.m | ||
@@ -36,6 +36,7 @@ | ||
const NSInteger SQRLInstallerErrorInvalidState = -6; | ||
const NSInteger SQRLInstallerErrorMovingAcrossVolumes = -7; | ||
const NSInteger SQRLInstallerErrorChangingPermissions = -8; | ||
+const NSInteger SQRLInstallerErrorAppStillRunning = -9; | ||
|
||
NSString * const SQRLShipItInstallationAttemptsKey = @"SQRLShipItInstallationAttempts"; | ||
NSString * const SQRLInstallerOwnedBundleKey = @"SQRLInstallerOwnedBundle"; | ||
@@ -286,6 +287,19 @@ - (RACSignal *)installRequest:(SQRLShipItRequest *)request { | ||
return [[[[self | ||
renameIfNeeded:request updateBundleURL:updateBundleURL] | ||
flattenMap:^(SQRLShipItRequest *request) { | ||
+ // Final validation that the application is not running again; | ||
+ NSArray *apps = [[NSRunningApplication runningApplicationsWithBundleIdentifier:request.bundleIdentifier] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSRunningApplication *app, NSDictionary *bindings) { | ||
+ return [[[app bundleURL] URLByStandardizingPath] isEqual:request.targetBundleURL]; | ||
+ }]]; | ||
+ if ([apps count] != 0) { | ||
+ NSLog(@"Aborting update attempt because there are %lu running instances of the target app", [apps count]); | ||
+ NSDictionary *errorInfo = @{ | ||
+ NSLocalizedDescriptionKey: NSLocalizedString(@"App Still Running Error", nil), | ||
+ NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"All instances of the target application should be quit during the update process", nil), | ||
+ }; | ||
+ return [RACSignal error:[NSError errorWithDomain:SQRLInstallerErrorDomain code:SQRLInstallerErrorAppStillRunning userInfo:errorInfo]]; | ||
+ } | ||
+ | ||
return [[self acquireTargetBundleURLForRequest:request] concat:[RACSignal return:request]]; | ||
}] | ||
flattenMap:^(SQRLShipItRequest *request) { | ||
diff --git a/Squirrel/ShipIt-main.m b/Squirrel/ShipIt-main.m | ||
index 2c515ffdd67052a08ee8155c0e46b57e9721a0e5..5f3e29642012d04fc506b730a4e87fba861df250 100644 | ||
--- a/Squirrel/ShipIt-main.m | ||
+++ b/Squirrel/ShipIt-main.m | ||
@@ -201,8 +201,14 @@ static void installRequest(RACSignal *readRequestSignal, NSString *applicationId | ||
return action; | ||
}] | ||
subscribeError:^(NSError *error) { | ||
- NSLog(@"Installation error: %@", error); | ||
- exit(EXIT_FAILURE); | ||
+ if ([[error domain] isEqual:SQRLInstallerErrorDomain] && [error code] == SQRLInstallerErrorAppStillRunning) { | ||
+ NSLog(@"Installation cancelled: %@", error); | ||
+ clearInstallationAttempts(applicationIdentifier); | ||
+ exit(EXIT_SUCCESS); | ||
+ } else { | ||
+ NSLog(@"Installation error: %@", error); | ||
+ exit(EXIT_FAILURE); | ||
+ } | ||
} completed:^{ | ||
exit(EXIT_SUCCESS); | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters