diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 7f4e30b5..eaf7c666 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -150,6 +150,10 @@ 721C24621CB75C68005440CB /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; 721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; + 721D588D25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */; }; + 721D588E25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */; }; + 721D588F25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */; }; + 721D589025BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */; }; 721D8A611D48413B0032E472 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 721D8A721D4950B80032E472 /* Autoupdate in Copy Tools */ = {isa = PBXBuildFile; fileRef = 72B398D21D3D879300EE297F /* Autoupdate */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 721D8A7B1D4963190032E472 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; @@ -1028,6 +1032,8 @@ 721C24451CB753E6005440CB /* Updater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Updater.app; sourceTree = BUILT_PRODUCTS_DIR; }; 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerProgress.xcconfig; sourceTree = ""; }; 721C24581CB7567D005440CB /* InstallerProgress-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "InstallerProgress-Info.plist"; path = "Sparkle/InstallerProgress/InstallerProgress-Info.plist"; sourceTree = SOURCE_ROOT; }; + 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPhasedUpdateGroupInfo.h; sourceTree = ""; }; + 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPhasedUpdateGroupInfo.m; sourceTree = ""; }; 721D8A831D498F1D0032E472 /* set-agent-signing.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "set-agent-signing.sh"; sourceTree = ""; }; 721D8A881D4D272E0032E472 /* Installation.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Installation.md; sourceTree = ""; }; 722194511D3BF987004C34FF /* SPUInstallerAgentProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SPUInstallerAgentProtocol.h; path = Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h; sourceTree = SOURCE_ROOT; }; @@ -1862,6 +1868,8 @@ 61B5FB9509C4F04600B25A18 /* SUAppcast.m */, 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */, + 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */, + 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */, 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */, @@ -2380,6 +2388,7 @@ 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, + 721D588E25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */, 72A5D5F91D692F4C0009E5AC /* SPUStatusCompletionResults.h in Headers */, 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */, EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */, @@ -2464,6 +2473,7 @@ 72A1C2631CD6849C004CD282 /* SUUpdatePermissionPrompt.h in Headers */, 72A450531C69A68900D67EEA /* SUUpdatePermissionResponse.h in Headers */, 72F9EBE21D517E2F004AC8B6 /* SUUpdater.h in Headers */, + 721D588D25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */, 72A6F98A1C94E2D6005F404C /* SUUpdaterDelegate.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */, @@ -3503,6 +3513,7 @@ 72A5D5C01D6929F80009E5AC /* SUConstants.m in Sources */, 72A5D5C21D6929F80009E5AC /* SUFileManager.m in Sources */, 72A5D5C11D6929F80009E5AC /* SUHost.m in Sources */, + 721D589025BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m in Sources */, 72A5D5B01D6929F80009E5AC /* SUInstallerConnection.m in Sources */, 72A5D5AE1D6929F80009E5AC /* SUInstallerLauncher.m in Sources */, 72B3DED01E23479000457642 /* SPUInformationalUpdate.m in Sources */, @@ -3597,6 +3608,7 @@ 61B5F8EE09C4CE3C00B25A18 /* SPUUpdater.m in Sources */, 720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */, 726E078E1CA891E9001A286B /* SPUUpdaterSettings.m in Sources */, + 721D588F25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m in Sources */, 72F9EC401D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */, 72B09CE81CE6BCBD0052EF9E /* SPUURLDownload.m in Sources */, 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */, diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index d1647ce4..83cb55b4 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -20,6 +20,7 @@ #import "SUAppcastItem.h" #import "SULocalizations.h" #import "SPUInstallationType.h" +#import "SUPhasedUpdateGroupInfo.h" #include "AppKitPrevention.h" @@ -200,6 +201,13 @@ - (void)downloadDriverDidDownloadUpdate:(SPUDownloadedUpdate *)downloadedUpdate { + // Use a new update group for our next downloaded update + // We could restrict this to when the appcast was downloaded in the background, + // but it shouldn't matter. + if (downloadedUpdate.updateItem.phasedRolloutInterval != nil) { + [SUPhasedUpdateGroupInfo setNewUpdateGroupIdentifierForHost:self.host]; + } + self.resumableUpdate = downloadedUpdate; [self extractUpdate:downloadedUpdate]; } diff --git a/Sparkle/SUAppcast.h b/Sparkle/SUAppcast.h index cc9fd386..5ae0f0fa 100644 --- a/Sparkle/SUAppcast.h +++ b/Sparkle/SUAppcast.h @@ -29,6 +29,7 @@ SU_EXPORT @interface SUAppcast : NSObject - (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)bg completionBlock:(void (^)(NSError *_Nullable))err; - (SUAppcast *)copyWithoutDeltaUpdates; +- (SUAppcast *)copyByFilteringItems:(BOOL (^)(SUAppcastItem *))filterBlock; @property (readonly, copy, nullable) NSArray *items; @end diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 8f1fb8f4..640960e8 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -307,14 +307,23 @@ } - (SUAppcast *)copyWithoutDeltaUpdates { + return [self copyByFilteringItems:^(SUAppcastItem *item) { + return (BOOL)![item isDeltaUpdate]; + }]; +} + +- (SUAppcast *)copyByFilteringItems:(BOOL (^)(SUAppcastItem *))filterBlock +{ SUAppcast *other = [SUAppcast new]; - NSMutableArray *nonDeltaItems = [NSMutableArray new]; - - for(SUAppcastItem *item in self.items) { - if (![item isDeltaUpdate]) [nonDeltaItems addObject:item]; + NSMutableArray *newItems = [NSMutableArray new]; + + for (SUAppcastItem *item in self.items) { + if (filterBlock(item)) { + [newItems addObject:item]; + } } - - other.items = nonDeltaItems; + + other.items = newItems; return other; } diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 38949b1d..a11c9df3 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -15,6 +15,7 @@ #import "SPUUpdaterDelegate.h" #import "SUHost.h" #import "SUConstants.h" +#import "SUPhasedUpdateGroupInfo.h" #include "AppKitPrevention.h" @@ -62,39 +63,42 @@ if (error != nil) { [self.delegate didFailToFetchAppcastWithError:error]; } else { - [self appcastDidFinishLoading:appcast includesSkippedUpdates:includesSkippedUpdates]; + [self appcastDidFinishLoading:appcast inBackground:background includesSkippedUpdates:includesSkippedUpdates]; } }]; } -- (void)appcastDidFinishLoading:(SUAppcast *)ac includesSkippedUpdates:(BOOL)includesSkippedUpdates +- (void)appcastDidFinishLoading:(SUAppcast *)loadedAppcast inBackground:(BOOL)background includesSkippedUpdates:(BOOL)includesSkippedUpdates { - [self.delegate didFinishLoadingAppcast:ac]; + [self.delegate didFinishLoadingAppcast:loadedAppcast]; - NSDictionary *userInfo = @{ SUUpdaterAppcastNotificationKey: ac }; + NSDictionary *userInfo = @{ SUUpdaterAppcastNotificationKey: loadedAppcast }; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:self.updater userInfo:userInfo]; + NSNumber *phasedUpdateGroup = background ? @([SUPhasedUpdateGroupInfo updateGroupForHost:self.host]) : nil; + SUAppcast *supportedAppcast = [[self class] filterSupportedAppcast:loadedAppcast phasedUpdateGroup:phasedUpdateGroup]; + SUAppcastItem *item = nil; SUAppcastItem *nonDeltaUpdateItem = nil; // Now we have to find the best valid update in the appcast. if ([self.updaterDelegate respondsToSelector:@selector((bestValidUpdateInAppcast:forUpdater:))]) { - item = [self.updaterDelegate bestValidUpdateInAppcast:ac forUpdater:(id _Nonnull)self.updater]; + item = [self.updaterDelegate bestValidUpdateInAppcast:supportedAppcast forUpdater:(id _Nonnull)self.updater]; } if (item != nil) { // Does the delegate want to handle it? if ([item isDeltaUpdate]) { - nonDeltaUpdateItem = [self.updaterDelegate bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id _Nonnull)self.updater]; + nonDeltaUpdateItem = [self.updaterDelegate bestValidUpdateInAppcast:[supportedAppcast copyWithoutDeltaUpdates] forUpdater:(id _Nonnull)self.updater]; } } else // If not, we'll take care of it ourselves. { // Find the best supported update SUAppcastItem *deltaUpdateItem = nil; - item = [[self class] bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; + item = [[self class] bestItemFromAppcastItems:supportedAppcast.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; if (item && deltaUpdateItem) { nonDeltaUpdateItem = item; @@ -102,7 +106,7 @@ } } - if ([self itemContainsValidUpdate:item includesSkippedUpdates:includesSkippedUpdates]) { + if ([self itemContainsValidUpdate:item inBackground:background includesSkippedUpdates:includesSkippedUpdates]) { self.nonDeltaUpdateItem = nonDeltaUpdateItem; [self.delegate didFindValidUpdateWithAppcastItem:item preventsAutoupdate:[self itemPreventsAutoupdate:item]]; } else { @@ -110,20 +114,30 @@ } } +// This method is used by unit tests ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup +{ + NSDate *currentDate = [NSDate date]; + + return [appcast copyByFilteringItems:^(SUAppcastItem *item) { + return (BOOL)([[self class] itemOperatingSystemIsOK:item] && [[self class] itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate]); + }]; +} + +// This method is used by unit tests +// This method should not do *any* filtering, only version comparing + (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { SUAppcastItem *item = nil; for(SUAppcastItem *candidate in appcastItems) { - if ([[self class] hostSupportsItem:candidate]) { - if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { - item = candidate; - } + if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { + item = candidate; } } if (item && deltaItem) { SUAppcastItem *deltaUpdateItem = [item deltaUpdates][hostVersion]; - if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { + if (deltaUpdateItem) { *deltaItem = deltaUpdateItem; } } @@ -131,7 +145,7 @@ return item; } -+ (BOOL)hostSupportsItem:(SUAppcastItem *)ui ++ (BOOL)itemOperatingSystemIsOK:(SUAppcastItem *)ui { BOOL osOK = [ui isMacOsUpdate]; if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && @@ -139,9 +153,10 @@ return osOK; } - BOOL minimumVersionOK = TRUE; - BOOL maximumVersionOK = TRUE; + BOOL minimumVersionOK = YES; + BOOL maximumVersionOK = YES; + // We don't want to use delegate's comparator for comparing OS versions id versionComparator = [[SUStandardVersionComparator alloc] init]; // Check minimum and maximum System Version @@ -189,9 +204,51 @@ return [[self versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending; } -- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui includesSkippedUpdates:(BOOL)includesSkippedUpdates ++ (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate { - return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && (includesSkippedUpdates || ![self itemContainsSkippedVersion:ui]); + if (phasedUpdateGroup == nil || [ui isCriticalUpdate]) { + return YES; + } + + NSNumber *phasedRolloutIntervalObject = [ui phasedRolloutInterval]; + if (phasedRolloutIntervalObject == nil) { + return YES; + } + + NSDate* itemReleaseDate = ui.date; + if (itemReleaseDate == nil) { + return YES; + } + + NSTimeInterval timeSinceRelease = [currentDate timeIntervalSinceDate:itemReleaseDate]; + + NSTimeInterval phasedRolloutInterval = [phasedRolloutIntervalObject doubleValue]; + NSTimeInterval timeToWaitForGroup = phasedRolloutInterval * phasedUpdateGroup.unsignedIntegerValue; + + if (timeSinceRelease >= timeToWaitForGroup) { + return YES; + } + + return NO; +} + +- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui inBackground:(BOOL)background includesSkippedUpdates:(BOOL)includesSkippedUpdates +{ + if (ui == nil) { + return NO; + } + + // Check that we have a newer appcast item than host + if (![self isItemNewer:ui]) { + return NO; + } + + // Check for skipped updates + if (!includesSkippedUpdates && [self itemContainsSkippedVersion:ui]) { + return NO; + } + + return YES; } @end diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index c722e53d..d6ad8ce5 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -23,6 +23,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *title; @property (copy, readonly) NSString *dateString; +@property (copy, readonly) NSDate *date; @property (copy, readonly) NSString *itemDescription; @property (strong, readonly) NSURL *releaseNotesURL; @property (strong, readonly) SUSignatures *signatures; @@ -35,6 +36,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *displayVersionString; @property (copy, readonly) NSDictionary *deltaUpdates; @property (strong, readonly) NSURL *infoURL; +@property (copy, readonly) NSNumber* phasedRolloutInterval; @property (nonatomic, copy, readonly) NSString *installationType; @property (copy, readonly) NSString *minimumAutoupdateVersion; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 71c3f07f..d58efc76 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -50,6 +50,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT @synthesize propertiesDictionary = _propertiesDictionary; @synthesize installationType = _installationType; @synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion; +@synthesize phasedRolloutInterval = _phasedRolloutInterval; + (BOOL)supportsSecureCoding { @@ -83,6 +84,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT _versionString = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemVersionStringKey] copy]; _osString = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastAttributeOsType] copy]; _propertiesDictionary = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class], [NSString class], [NSDate class], [NSArray class]]] forKey:SUAppcastItemPropertiesKey]; + _phasedRolloutInterval = [decoder decodeObjectOfClass:[NSNumber class] forKey:SUAppcastElementPhasedRolloutInterval]; } return self; @@ -151,6 +153,10 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT if (self.installationType != nil) { [encoder encodeObject:self.installationType forKey:SUAppcastItemInstallationTypeKey]; } + + if (self.phasedRolloutInterval != nil) { + [encoder encodeObject:self.phasedRolloutInterval forKey:SUAppcastElementPhasedRolloutInterval]; + } } - (BOOL)isDeltaUpdate @@ -169,6 +175,19 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return self.osString == nil || [self.osString isEqualToString:SUAppcastAttributeValueMacOS]; } +- (NSDate *)date +{ + if (self.dateString == nil) { + return nil; + } + + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + dateFormatter.dateFormat = @"E, dd MMM yyyy HH:mm:ss Z"; + + return [dateFormatter dateFromString:self.dateString]; +} + - (BOOL)isInformationOnlyUpdate { return self.infoURL && !self.fileURL; @@ -275,6 +294,11 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT _minimumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumSystemVersion] copy]; _maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy]; _minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy]; + + NSString* rolloutIntervalString = [(NSString *)[dict objectForKey:SUAppcastElementPhasedRolloutInterval] copy]; + if (rolloutIntervalString != nil) { + _phasedRolloutInterval = @(rolloutIntervalString.integerValue); + } NSString *shortVersionString = [enclosure objectForKey:SUAppcastAttributeShortVersionString]; if (nil == shortVersionString) { diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index e765fc3b..7f5b8246 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -52,6 +52,7 @@ extern NSString *const SUAllowsAutomaticUpdatesKey; extern NSString *const SUEnableAutomaticChecksKey; extern NSString *const SUEnableSystemProfilingKey; extern NSString *const SUSendProfileInfoKey; +extern NSString *const SUUpdateGroupIdentifierKey; extern NSString *const SULastProfileSubmitDateKey; extern NSString *const SUPromptUserOnFirstLaunchKey; extern NSString *const SUDefaultsDomainKey; @@ -81,6 +82,7 @@ extern NSString *const SUAppcastElementMinimumSystemVersion; extern NSString *const SUAppcastElementMaximumSystemVersion; extern NSString *const SUAppcastElementReleaseNotesLink; extern NSString *const SUAppcastElementTags; +extern NSString *const SUAppcastElementPhasedRolloutInterval; extern NSString *const SURSSAttributeURL; extern NSString *const SURSSAttributeLength; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 1a055784..990244f1 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -47,6 +47,7 @@ NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo"; +NSString *const SUUpdateGroupIdentifierKey = @"SUUpdateGroupIdentifier"; NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch"; NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript"; @@ -74,6 +75,7 @@ NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVe NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion"; NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink"; NSString *const SUAppcastElementTags = @"sparkle:tags"; +NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval"; NSString *const SURSSAttributeURL = @"url"; NSString *const SURSSAttributeLength = @"length"; diff --git a/Sparkle/SUPhasedUpdateGroupInfo.h b/Sparkle/SUPhasedUpdateGroupInfo.h new file mode 100644 index 00000000..6f54c7a3 --- /dev/null +++ b/Sparkle/SUPhasedUpdateGroupInfo.h @@ -0,0 +1,22 @@ +// +// SUPhasedUpdateGroupInfo.h +// Sparkle +// +// Created by Mayur Pawashe on 01/24/21. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SUHost; + +@interface SUPhasedUpdateGroupInfo : NSObject + ++ (NSUInteger)updateGroupForHost:(SUHost*)host; ++ (NSNumber*)setNewUpdateGroupIdentifierForHost:(SUHost*)host; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUPhasedUpdateGroupInfo.m b/Sparkle/SUPhasedUpdateGroupInfo.m new file mode 100644 index 00000000..48e84892 --- /dev/null +++ b/Sparkle/SUPhasedUpdateGroupInfo.m @@ -0,0 +1,42 @@ +// +// SUPhasedUpdateGroupInfo.m +// Sparkle +// +// Created by Mayur Pawashe on 01/24/21. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUPhasedUpdateGroupInfo.h" +#import "SUHost.h" +#import "SUConstants.h" + + +#include "AppKitPrevention.h" + +@implementation SUPhasedUpdateGroupInfo + +#define NUM_UPDATE_GROUPS 7 ++ (NSUInteger)updateGroupForHost:(SUHost*)host { + NSNumber* updateGroupIdentifier = [self updateGroupIdentifierForHost:host]; + return ([updateGroupIdentifier unsignedIntValue] % NUM_UPDATE_GROUPS); +} + ++ (NSNumber*)updateGroupIdentifierForHost:(SUHost*)host { + NSNumber* updateGroupIdentifier = [host objectForUserDefaultsKey:SUUpdateGroupIdentifierKey]; + if(updateGroupIdentifier == nil) { + updateGroupIdentifier = [self setNewUpdateGroupIdentifierForHost:host]; + } + + return updateGroupIdentifier; +} + ++ (NSNumber*)setNewUpdateGroupIdentifierForHost:(SUHost*)host { + unsigned int r = arc4random_uniform(UINT_MAX); + NSNumber* updateGroupIdentifier = @(r); + + [host setObject:updateGroupIdentifier forUserDefaultsKey:SUUpdateGroupIdentifierKey]; + + return updateGroupIdentifier; +} + +@end diff --git a/Sparkle/SUSystemUpdateInfo.h b/Sparkle/SUSystemUpdateInfo.h deleted file mode 100644 index 28f89978..00000000 --- a/Sparkle/SUSystemUpdateInfo.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// SUSystemUpdateInfo.h -// Sparkle -// -// Created by Mayur Pawashe on 12/23/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class SUHost; - -@interface SUSystemUpdateInfo : NSObject - -+ (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUSystemUpdateInfo.m b/Sparkle/SUSystemUpdateInfo.m deleted file mode 100644 index 78325eae..00000000 --- a/Sparkle/SUSystemUpdateInfo.m +++ /dev/null @@ -1,61 +0,0 @@ -// -// SUSystemUpdateInfo.m -// Sparkle -// -// Created by Mayur Pawashe on 12/23/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SUSystemUpdateInfo.h" -#import "SUHost.h" -#import "SUConstants.h" -#import "SUFileManager.h" - - -#include "AppKitPrevention.h" - -@implementation SUSystemUpdateInfo - -+ (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host -{ - // Does the developer want us to disable automatic updates? - NSNumber *developerAllowsAutomaticUpdates = [host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; - if (developerAllowsAutomaticUpdates != nil && !developerAllowsAutomaticUpdates.boolValue) { - return NO; - } - - // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? - // Note it's very well possible to have the bundle be writable but not be able to write into the parent directory - // And if the bundle isn't writable, but we can write into the parent directory, we will still need to authorize to replace it - NSString *bundlePath = [host bundlePath]; - if (![[NSFileManager defaultManager] isWritableFileAtPath:bundlePath.stringByDeletingLastPathComponent] || ![[NSFileManager defaultManager] isWritableFileAtPath:bundlePath]) { - return NO; - } - - // Just because we have writability access does not mean we can set the correct owner/group silently - // Test if we can set the owner/group on a temporarily created file - // If we can, then we can probably perform an update without authorization - // One place where this matters is if you copy and run an app from /tmp/ - - NSString *tempFilename = @"permission_test" ; - - SUFileManager *suFileManager = [SUFileManager defaultManager]; - NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL]; - - if (tempDirectoryURL == nil) { - // I don't imagine this ever happening but in case it does, requesting authorization may be the better option - return NO; - } - - NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename]; - - BOOL changeOwnerAndGroupSuccess = - [[NSData data] writeToURL:tempFileURL atomically:NO] && - [suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:host.bundle.bundleURL error:NULL]; - - [suFileManager removeItemAtURL:tempDirectoryURL error:NULL]; - - return changeOwnerAndGroupSuccess; -} - -@end diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 602b611c..ca90549f 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -24,7 +24,6 @@ #import "SPUDownloadData.h" #import "SUApplicationInfo.h" #import "SPUUpdaterSettings.h" -#import "SUSystemUpdateInfo.h" #import "SUTouchBarForwardDeclarations.h" #import "SUTouchBarButtonGroup.h" #import "SPUXPCServiceInfo.h" diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index a7ed80a5..d602ba7b 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -12,6 +12,7 @@ Version 3.0 + 86400 )comparator; ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup; + @end