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/)
This commit is contained in:
Zorg committed 2016-08-10 20:29:10 -04:00
1 parent 11cbecbeaa
commit 69db74bc36
1 file changed
+5 -4
+5 -4
View File
@@ -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<NSString *> *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;
}
}