From e6a344a570bcf1e988a294c85c9645f83f294dce Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 5 Jun 2026 18:45:52 -0700 Subject: [PATCH] Fix updating not working the first time if bundle ID ends with ".app" (#2882) Use a different app cache directory if bundle ID ends with ".app" so that the cache directory Sparkle writes into does not look like an app bundle and cause other systematic issues. This can occur if a developer uses an ill-formed bundle identifier rather than conventional reverse-DNS one. --- Sparkle/SPULocalCacheDirectory.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPULocalCacheDirectory.m b/Sparkle/SPULocalCacheDirectory.m index 0a2753d7..974abb16 100644 --- a/Sparkle/SPULocalCacheDirectory.m +++ b/Sparkle/SPULocalCacheDirectory.m @@ -18,7 +18,17 @@ static NSTimeInterval OLD_ITEM_DELETION_INTERVAL = 86400 * 10; // 10 days + (NSString *)_cachePathForCacheDirectory:(NSURL *)cacheURL bundleIdentifier:(NSString *)bundleIdentifier SPU_OBJC_DIRECT { - NSString *resultPath = [[[cacheURL URLByAppendingPathComponent:bundleIdentifier isDirectory:YES] URLByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER isDirectory:YES] path]; + // If an app has an ill-formed bundle identifier that ends with ".app" we will append ".sparkle" to it + // so that the cache directory doesn't look like an app bundle directory, which can cause other systematic issues + // https://github.com/sparkle-project/Sparkle/discussions/2881 + NSString *appCacheIdentifier; + if ([bundleIdentifier hasSuffix:@".app"] || [bundleIdentifier hasSuffix:@".APP"]) { + appCacheIdentifier = [bundleIdentifier stringByAppendingString:@".sparkle"]; + } else { + appCacheIdentifier = bundleIdentifier; + } + + NSString *resultPath = [[[cacheURL URLByAppendingPathComponent:appCacheIdentifier isDirectory:YES] URLByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER isDirectory:YES] path]; assert(resultPath != nil); return resultPath; @@ -90,6 +100,8 @@ static NSTimeInterval OLD_ITEM_DELETION_INTERVAL = 86400 * 10; // 10 days if ([templateString getFileSystemRepresentation:buffer maxLength:sizeof(buffer)]) { if (mkdtemp(buffer) != NULL) { return [[NSString alloc] initWithUTF8String:buffer]; + } else { + SULog(SULogLevelError, @"Failed to create templated intermediate cache directory using mkdtemp() with error: %d", errno); } } return nil;