Browse Source

fix: edge case in app.isInApplicationsFolder() (#35729)

trop[bot] 2 years ago
parent
commit
2dfd69ea90
1 changed files with 11 additions and 2 deletions
  1. 11 2
      shell/browser/ui/cocoa/electron_bundle_mover.mm

+ 11 - 2
shell/browser/ui/cocoa/electron_bundle_mover.mm

@@ -182,18 +182,27 @@ bool ElectronBundleMover::IsCurrentAppInApplicationsFolder() {
   return IsInApplicationsFolder([[NSBundle mainBundle] bundlePath]);
 }
 
+NSString* resolvePath(NSString* path) {
+  NSString* standardizedPath = [path stringByStandardizingPath];
+  char resolved[PATH_MAX];
+  if (realpath([standardizedPath UTF8String], resolved) == NULL)
+    return path;
+  return @(resolved);
+}
+
 bool ElectronBundleMover::IsInApplicationsFolder(NSString* bundlePath) {
   // Check all the normal Application directories
   NSArray* applicationDirs = NSSearchPathForDirectoriesInDomains(
       NSApplicationDirectory, NSAllDomainsMask, true);
+  NSString* resolvedBundlePath = resolvePath(bundlePath);
   for (NSString* appDir in applicationDirs) {
-    if ([bundlePath hasPrefix:appDir])
+    if ([resolvedBundlePath hasPrefix:appDir])
       return true;
   }
 
   // Also, handle the case that the user has some other Application directory
   // (perhaps on a separate data partition).
-  if ([[bundlePath pathComponents] containsObject:@"Applications"])
+  if ([[resolvedBundlePath pathComponents] containsObject:@"Applications"])
     return true;
 
   return false;