зеркало из https://github.com/electron/electron.git
fix: edge case in app.isInApplicationsFolder() (#35636)
* fix: edge case in IsInApplicationsFolder * use realpath instead * lint * revert lowercasing * optimize * Update shell/browser/ui/cocoa/electron_bundle_mover.mm * lint Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Родитель
01cf5c5f99
Коммит
76ce6d5fb4
|
@ -182,18 +182,27 @@ bool ElectronBundleMover::IsCurrentAppInApplicationsFolder() {
|
||||||
return IsInApplicationsFolder([[NSBundle mainBundle] bundlePath]);
|
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) {
|
bool ElectronBundleMover::IsInApplicationsFolder(NSString* bundlePath) {
|
||||||
// Check all the normal Application directories
|
// Check all the normal Application directories
|
||||||
NSArray* applicationDirs = NSSearchPathForDirectoriesInDomains(
|
NSArray* applicationDirs = NSSearchPathForDirectoriesInDomains(
|
||||||
NSApplicationDirectory, NSAllDomainsMask, true);
|
NSApplicationDirectory, NSAllDomainsMask, true);
|
||||||
|
NSString* resolvedBundlePath = resolvePath(bundlePath);
|
||||||
for (NSString* appDir in applicationDirs) {
|
for (NSString* appDir in applicationDirs) {
|
||||||
if ([bundlePath hasPrefix:appDir])
|
if ([resolvedBundlePath hasPrefix:appDir])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also, handle the case that the user has some other Application directory
|
// Also, handle the case that the user has some other Application directory
|
||||||
// (perhaps on a separate data partition).
|
// (perhaps on a separate data partition).
|
||||||
if ([[bundlePath pathComponents] containsObject:@"Applications"])
|
if ([[resolvedBundlePath pathComponents] containsObject:@"Applications"])
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче