Permalink
Browse files

Improving Sparkle's robustness against apps without a CFBundleVersion.

  • Loading branch information...
1 parent 34586bc commit 7071142aad583e254c07d365e53574edad874e77 @andymatuschak andymatuschak committed Jan 10, 2009
Showing with 10 additions and 7 deletions.
  1. +1 −1 Configurations/ConfigCommonDebug.xcconfig
  2. +1 −1 SUBasicUpdateDriver.m
  3. +4 −1 SUHost.m
  4. +4 −4 SUPlainInstallerInternals.m
@@ -5,4 +5,4 @@ DEBUG_INFORMATION_FORMAT = dwarf
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
SPARKLE_EXTRA_DEBUG = -DDEBUG -fstack-protector -D_FORTIFY_SOURCE=2
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
-ARCHS = $(NATIVE_ARCH_ACTUAL)
+//ARCHS = $(NATIVE_ARCH_ACTUAL)
View
@@ -142,7 +142,7 @@ - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSSt
NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]];
NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
int cnt=1;
- while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999999)
+ while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]];
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
if (!success)
View
@@ -55,7 +55,10 @@ - (NSString *)name
- (NSString *)version
{
- return [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
+ NSString *version = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
+ if (!version || [version isEqualToString:@""])
+ [NSException raise:@"SUNoVersionException" format:@"This host (%@) has no CFBundleVersion! This attribute is required.", [self bundlePath]];
+ return version;
}
- (NSString *)displayVersion
@@ -99,22 +99,22 @@ + (NSString *)_temporaryCopyNameForPath:(NSString *)path
{
// Let's try to read the version number so the filename will be more meaningful.
NSString *postFix;
- NSBundle *bundle;
- if ((bundle = [NSBundle bundleWithPath:path]))
+ NSString *version;
+ if ((version = [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]) && ![version isEqualToString:@""])
{
// We'll clean it up a little for safety.
// The cast is necessary because of a bug in the headers in pre-10.5 SDKs
NSMutableCharacterSet *validCharacters = (id)[NSMutableCharacterSet alphanumericCharacterSet];
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
- postFix = [[bundle objectForInfoDictionaryKey:@"CFBundleVersion"] stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
+ postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
}
else
postFix = @"old";
NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix];
NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]];
// Now let's make sure we get a unique path.
int cnt=2;
- while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999999)
+ while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
tempDir = [NSString stringWithFormat:@"%@ %d.%@", prefix, cnt++, [path pathExtension]];
return tempDir;
}

0 comments on commit 7071142

Please sign in to comment.