From a2ecdd2744724aabf0c5caf866a84e24b6c02496 Mon Sep 17 00:00:00 2001 From: Jonathan Bullard Date: Thu, 5 Oct 2017 08:57:04 -0400 Subject: [PATCH 1/2] Fix #1061 & #835: Sparkle clients polling too frequently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SULastCheckTimeKey preference (a/k/a "default"), which is stored in ~/Library/Preferences/….plist, was used to store the date of the last update check. That causes a problem if the storage is read-only (for example, if the .plist file is “locked” (has the uchg or schg flag set) or if the SULastCheckTimeKey key "exists in a domain that precedes the application domain the search list"). The date would never be modified, and the old date would cause a new update check to be queued at the end of an update check. If application or bundle was up-to-date, or the user had chosen to skip the update that was available, this would cause update checks to happen as often as the computer and network would allow, many times each second. The new code uses an instance variable to store the value. The variable is initially loaded from the “SULastCheckTimeKey” preference, and each time the variable is modified its new value is stored to that preference. However, the variable, not the preference, is used when calculating whether enough time has passed since the last update check to warrant another check. The variable will always (after the first update check) have the "correct" value, and update checks will not be done more frequently than desired. --- Sparkle/SUUpdater.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index b20d9499..3c8d9c32 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -49,6 +49,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @property (strong) SUUpdateDriver *driver; @property (strong) SUHost *host; +@property (copy) NSDate *updateLastCheckedDate; + @end @implementation SUUpdater @@ -61,6 +63,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize host; @synthesize sparkleBundle; @synthesize decryptionPassword; +@synthesize updateLastCheckedDate; static NSMutableDictionary *sharedUpdaters = nil; static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; @@ -253,13 +256,20 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (NSDate *)lastUpdateCheckDate { - return [self.host objectForUserDefaultsKey:SULastCheckTimeKey]; + if (![self updateLastCheckedDate]) + { + [self setUpdateLastCheckedDate:[self.host objectForUserDefaultsKey:SULastCheckTimeKey]]; + } + + return [self updateLastCheckedDate]; } - (void)updateLastUpdateCheckDate { + [self setUpdateLastCheckedDate:[NSDate date]]; + [self willChangeValueForKey:@"lastUpdateCheckDate"]; - [self.host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey]; + [self.host setObject:[self updateLastCheckedDate] forUserDefaultsKey:SULastCheckTimeKey]; [self didChangeValueForKey:@"lastUpdateCheckDate"]; } From 10f831fce870a98e630f517a488918333279e4d9 Mon Sep 17 00:00:00 2001 From: Jonathan Bullard Date: Thu, 5 Oct 2017 09:36:31 -0400 Subject: [PATCH 2/2] Move [NSDate date] to be after willChangeValueForKey Per comment by Pornel --- Sparkle/SUUpdater.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 3c8d9c32..0cab3d6d 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -266,9 +266,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (void)updateLastUpdateCheckDate { - [self setUpdateLastCheckedDate:[NSDate date]]; - [self willChangeValueForKey:@"lastUpdateCheckDate"]; + [self setUpdateLastCheckedDate:[NSDate date]]; [self.host setObject:[self updateLastCheckedDate] forUserDefaultsKey:SULastCheckTimeKey]; [self didChangeValueForKey:@"lastUpdateCheckDate"]; }