mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
Find potential matching translocated running apps in updater agent (#2233)
In the installer progress agent, when we find all potential running applications for a host bundle, we should also consider any translocated running apps that look-alike the host bundle. This matters when updating external bundles. For example if sparkle-cli tries to update an app on disk in ~/Downloads/ but a running instance of the app is translocated, sparkle-cli should terminate the translocated instance of the app before installing the update. It's possible this could generate a false positive but we err on the side of safety here. We only use running translocated apps if we find no regular matching apps.
This commit is contained in:
1 file changed
+22
-6
+22
-6
@@ -224,18 +224,34 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
NSMutableArray<NSRunningApplication *> *matchedRunningApplications = [[NSMutableArray alloc] init];
|
||||
|
||||
if (bundleIdentifier != nil && bundlePathComponents != nil) {
|
||||
NSArray *runningApplications =
|
||||
(bundleIdentifier != nil) ?
|
||||
[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] :
|
||||
[[NSWorkspace sharedWorkspace] runningApplications];
|
||||
NSArray *runningApplications = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier];
|
||||
|
||||
// If we find any running application that is translocated and looks like the bundle, we should record those too
|
||||
// We will want to terminate those apps and observe their pids, but we will only do this if we don't find any regular matches
|
||||
NSMutableArray<NSRunningApplication *> *potentialMatchingTranslocatedRunningApplications = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSRunningApplication *runningApplication in runningApplications) {
|
||||
// Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead
|
||||
NSString *candidatePath = runningApplication.bundleURL.URLByResolvingSymlinksInPath.path;
|
||||
if (candidatePath != nil && [candidatePath.pathComponents isEqualToArray:bundlePathComponents]) {
|
||||
[matchedRunningApplications addObject:runningApplication];
|
||||
if (candidatePath != nil) {
|
||||
NSArray<NSString *> *candidatePathComponents = candidatePath.pathComponents;
|
||||
if ([candidatePathComponents isEqualToArray:bundlePathComponents]) {
|
||||
[matchedRunningApplications addObject:runningApplication];
|
||||
} else if (matchedRunningApplications.count == 0 && candidatePathComponents.count > 0 && bundlePathComponents.count > 0) {
|
||||
NSString *lastBundlePathComponent = bundlePathComponents.lastObject;
|
||||
NSString *lastCandidatePathComponent = candidatePathComponents.lastObject;
|
||||
if (lastBundlePathComponent != nil && lastCandidatePathComponent != nil && [lastBundlePathComponent isEqualToString:lastCandidatePathComponent] && [candidatePathComponents containsObject:@"AppTranslocation"]) {
|
||||
[potentialMatchingTranslocatedRunningApplications addObject:runningApplication];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Non-translocated apps take priority first
|
||||
// And we only use translocated version of apps if there are no regular apps matched
|
||||
if (matchedRunningApplications.count == 0) {
|
||||
[matchedRunningApplications addObjectsFromArray:potentialMatchingTranslocatedRunningApplications];
|
||||
}
|
||||
}
|
||||
|
||||
return [matchedRunningApplications copy];
|
||||
|
||||
Reference in new issue
Block a user