mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Avoid using host bundle filename for finding bundle to update (#2953)
The user can rename the host bundle filename so it's not reliable and gives a false sense of reliability. We keep matching against the name of the bundle derived from the Info.plist and the bundle identifier.
This commit is contained in:
28 files changed
+73
-27
No files matched your search
@@ -21,6 +21,17 @@
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
static BOOL SUFilenameMatchesAnyName(NSString *filename, NSOrderedSet<NSString *> *names)
|
||||
{
|
||||
for (NSString *name in names) {
|
||||
// This handles unicode normalization but is still a case sensitive comparison
|
||||
if ([filename compare:name] == NSOrderedSame) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
|
||||
@@ -32,8 +43,15 @@
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile,
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
*bundleExtension = [[host bundlePath] pathExtension];
|
||||
NSOrderedSet<NSString *> *hostNames = [host infoDictionaryNames];
|
||||
NSMutableOrderedSet<NSString *> *bundleFileNames = [NSMutableOrderedSet orderedSet];
|
||||
for (NSString *hostName in hostNames) {
|
||||
NSString *bundleFileName = [hostName stringByAppendingPathExtension:bundleExtension];
|
||||
if (bundleFileName != nil) {
|
||||
[bundleFileNames addObject:bundleFileName];
|
||||
}
|
||||
}
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
NSString *fallbackPackagePath = nil;
|
||||
|
||||
@@ -41,7 +59,6 @@
|
||||
BOOL isGuided = YES;
|
||||
#endif
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder];
|
||||
NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension];
|
||||
|
||||
while ((currentFile = [dirEnum nextObject])) {
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
@@ -78,8 +95,7 @@
|
||||
NSString *currentExtension = [currentFile pathExtension];
|
||||
NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension];
|
||||
#endif
|
||||
if ([currentFilename isEqualToString:bundleFileName] ||
|
||||
[currentFilename isEqualToString:alternateBundleFileName]) // We found one!
|
||||
if (SUFilenameMatchesAnyName(currentFilename, bundleFileNames)) // We found one!
|
||||
{
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage = NO;
|
||||
@@ -89,7 +105,7 @@
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
} else if ([currentExtension isEqualToString:@"pkg"] ||
|
||||
[currentExtension isEqualToString:@"mpkg"]) {
|
||||
if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) {
|
||||
if (SUFilenameMatchesAnyName(currentFilenameNoExtension, hostNames)) {
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
@@ -138,13 +154,13 @@
|
||||
#endif
|
||||
|
||||
if (!newAppDownloadPath) {
|
||||
SULog(SULogLevelError, @"Searched %@ for %@.(app%@)", inUpdateFolder, bundleFileNameNoExtension,
|
||||
SULog(SULogLevelError, @"Searched %@ for {%@}.(app%@) or bundle identifier %@", inUpdateFolder, [hostNames.array componentsJoinedByString:@", "],
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
@"|pkg"
|
||||
#else
|
||||
@""
|
||||
#endif
|
||||
);
|
||||
, host.bundle.bundleIdentifier);
|
||||
}
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -32,6 +32,7 @@ SUHostDefinitionAttribute
|
||||
|
||||
@property (readonly, nonatomic, copy) NSString *bundlePath;
|
||||
@property (readonly, nonatomic, copy) NSString *name;
|
||||
@property (readonly, nonatomic, copy) NSOrderedSet<NSString *> *infoDictionaryNames;
|
||||
@property (readonly, nonatomic, copy) NSString *version;
|
||||
@property (readonly, nonatomic) BOOL validVersion;
|
||||
@property (readonly, nonatomic, copy) NSString *displayVersion;
|
||||
|
||||
Vendored
+26
-11
@@ -140,19 +140,34 @@ static void *SUHostObservableContext = &SUHostObservableContext;
|
||||
return _bundle.bundlePath;
|
||||
}
|
||||
|
||||
- (NSOrderedSet<NSString *> *)infoDictionaryNamesStoppingAtFirstMatch:(BOOL)stopAtFirstMatch SPU_OBJC_DIRECT
|
||||
{
|
||||
NSMutableOrderedSet<NSString *> *names = [NSMutableOrderedSet orderedSet];
|
||||
// Allow host bundle to provide a custom name
|
||||
for (NSString *key in @[@"SUBundleName", @"CFBundleDisplayName", (__bridge NSString *)kCFBundleNameKey]) {
|
||||
NSString *name = [self objectForInfoDictionaryKey:key ofClass:NSString.class];
|
||||
if (name.length > 0) {
|
||||
[names addObject:name];
|
||||
|
||||
if (stopAtFirstMatch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [names copy];
|
||||
}
|
||||
|
||||
- (NSOrderedSet<NSString *> *)infoDictionaryNames
|
||||
{
|
||||
return [self infoDictionaryNamesStoppingAtFirstMatch:NO];
|
||||
}
|
||||
|
||||
- (NSString * _Nonnull)name
|
||||
{
|
||||
NSString *name;
|
||||
|
||||
// Allow host bundle to provide a custom name
|
||||
name = [self objectForInfoDictionaryKey:@"SUBundleName" ofClass:NSString.class];
|
||||
if (name && name.length > 0) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:@"CFBundleDisplayName" ofClass:NSString.class];
|
||||
if (name && name.length > 0) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey ofClass:NSString.class];
|
||||
if (name && name.length > 0) return name;
|
||||
NSString *name = [self infoDictionaryNamesStoppingAtFirstMatch:YES].firstObject;
|
||||
if (name != nil) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Both</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedBoth</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
-4
@@ -13,10 +13,6 @@
|
||||
<dict>
|
||||
<key>Resources/test-pubkey.pem</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
pR1EGsp5nhk1vr/xfQPT8es9ZBw=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
zD/XQJu4ElPWE6sfqtzoR2vEjdfgi98j/hiRoYZqv9w=
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedBothNew</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
-4
@@ -13,10 +13,6 @@
|
||||
<dict>
|
||||
<key>Resources/test-pubkey.pem</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
pR1EGsp5nhk1vr/xfQPT8es9ZBw=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
zD/XQJu4ElPWE6sfqtzoR2vEjdfgi98j/hiRoYZqv9w=
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedInvalid</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedInvalidOnly</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedOldED</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedOnly</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CodeSignedOnlyNew</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>DSAOnly</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>EDOnly</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>None</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
|
||||
Reference in new issue
Block a user