From 69db74bc3674f29ae1936e368ee3396ab2a5a9b9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 10 Aug 2016 20:29:10 -0400 Subject: [PATCH] Resolve symlinks when finding a matching running application path This fixes issues where Sparkle may think an application has already terminated when placed in a directory that has symlinks (such as /tmp/) --- Sparkle/SPUApplicationInfo.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sparkle/SPUApplicationInfo.m b/Sparkle/SPUApplicationInfo.m index 61bbcfdd..8ab91981 100644 --- a/Sparkle/SPUApplicationInfo.m +++ b/Sparkle/SPUApplicationInfo.m @@ -35,10 +35,11 @@ + (NSRunningApplication *)runningApplicationWithBundle:(NSBundle *)bundle { - NSString *bundlePath = bundle.bundlePath; + // Resolve symlinks otherwise when we compare file paths, we may not realize two paths that are represented differently are the same + NSArray *bundlePathComponents = bundle.bundlePath.stringByResolvingSymlinksInPath.pathComponents; NSString *bundleIdentifier = bundle.bundleIdentifier; - if (bundleIdentifier != nil && bundlePath != nil) { + if (bundleIdentifier != nil && bundlePathComponents != nil) { NSArray *runningApplications = (bundleIdentifier != nil) ? [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] : @@ -46,8 +47,8 @@ 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.path; - if (candidatePath != nil && [candidatePath isEqualToString:bundlePath]) { + NSString *candidatePath = runningApplication.bundleURL.URLByResolvingSymlinksInPath.path; + if (candidatePath != nil && [candidatePath.pathComponents isEqualToArray:bundlePathComponents]) { return runningApplication; } }