diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 083077c4..caecfbd0 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -526,10 +526,6 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [self scheduleNextUpdateCheck]; return; } - - // Reload our host bundle information in case its current cache is out of date - // We could have updated the bundle before for example without terminating this updater process - [self.host reloadInfoDictionary]; // Because an application can change the configuration (eg: the feed url) at any point, we should always check if it's valid NSError *configurationError = nil; diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 2f2b8fc8..6ddbd7c3 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -13,10 +13,6 @@ - (instancetype)initWithBundle:(NSBundle *)aBundle; -// Invalidates the info dictionary cache -// This is not thread safe -- (void)reloadInfoDictionary; - @property (readonly, copy) NSString *bundlePath; @property (readonly, copy) NSString *name; @property (readonly, copy) NSString *version; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 56cc1319..2faff0e9 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -24,18 +24,18 @@ @interface SUHost () @property (strong, readwrite) NSBundle *bundle; +@property (nonatomic, readonly) BOOL isMainBundle; @property (copy) NSString *defaultsDomain; @property (assign) BOOL usesStandardUserDefaults; -@property (nonatomic) NSDictionary *infoDictionary; @end @implementation SUHost @synthesize bundle; +@synthesize isMainBundle = _isMainBundle; @synthesize defaultsDomain; @synthesize usesStandardUserDefaults; -@synthesize infoDictionary = _infoDictionary; - (instancetype)initWithBundle:(NSBundle *)aBundle { @@ -47,7 +47,7 @@ SULog(SULogLevelError, @"Error: the bundle being updated at %@ has no %@! This will cause preference read/write to not work properly.", self.bundle, kCFBundleIdentifierKey); } - _infoDictionary = aBundle.infoDictionary; + _isMainBundle = [aBundle isEqualTo:[NSBundle mainBundle]]; self.defaultsDomain = [self objectForInfoDictionaryKey:SUDefaultsDomainKey]; if (!self.defaultsDomain) { @@ -61,14 +61,6 @@ return self; } -// NSBundles always cache the info dictionary, even if you create a new NSBundle instance, but we sometimes want to reload it -// in case the bundle changes or is updated -- (void)reloadInfoDictionary -{ - CFDictionaryRef infoDictionary = CFBundleCopyInfoDictionaryInDirectory((CFURLRef)self.bundle.bundleURL); - self.infoDictionary = CFBridgingRelease(infoDictionary); -} - - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self bundlePath]]; } - (NSString *)bundlePath @@ -163,7 +155,21 @@ - (id)objectForInfoDictionaryKey:(NSString *)key { - return [self.infoDictionary objectForKey:key]; + if (self.isMainBundle) { + // Common fast path - if we're updating the main bundle, that means our updater and host bundle's lifetime is the same + // If the bundle happens to be updated or change, that means our updater process needs to be terminated first to do it safely + // Thus we can rely on the cached Info dictionary + return [self.bundle objectForInfoDictionaryKey:key]; + } else { + // Slow path - if we're updating another bundle, we should read in the most up to date Info dictionary because + // the bundle can be replaced externally or even by us. + // This is the easiest way to read the Info dictionary values *correctly* despite some performance loss. + // A mutable method to reload the Info dictionary at certain points and have it cached at other points is challenging to do correctly. + CFDictionaryRef cfInfoDictionary = CFBundleCopyInfoDictionaryInDirectory((CFURLRef)self.bundle.bundleURL); + NSDictionary *infoDictionary = CFBridgingRelease(cfInfoDictionary); + + return [infoDictionary objectForKey:key]; + } } - (BOOL)boolForInfoDictionaryKey:(NSString *)key