Merge pull request #1736 from sparkle-project/phased-group-rollout-2x

Port phased group rollout to 2.x
This commit is contained in:
Mayur Pawashe authored and GitHub committed 2021-01-30 19:13:28 -08:00
commit c5add680aa
17 files changed
+216 -110

No files matched your search

+12
View File
@@ -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 = "<group>"; };
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 = "<group>"; };
721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPhasedUpdateGroupInfo.m; sourceTree = "<group>"; };
721D8A831D498F1D0032E472 /* set-agent-signing.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "set-agent-signing.sh"; sourceTree = "<group>"; };
721D8A881D4D272E0032E472 /* Installation.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Installation.md; sourceTree = "<group>"; };
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 */,
+8
View File
@@ -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];
}
+1
View File
@@ -29,6 +29,7 @@ SU_EXPORT @interface SUAppcast : NSObject<NSURLDownloadDelegate>
- (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
+15 -6
View File
@@ -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;
}
+75 -18
View File
@@ -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<SUVersionComparison>)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<SUVersionComparison> 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
+2
View File
@@ -23,6 +23,7 @@
SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
@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<NSSecureCoding>
@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;
+24
View File
@@ -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) {
+2
View File
@@ -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;
+2
View File
@@ -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";
+22
View File
@@ -0,0 +1,22 @@
//
// SUPhasedUpdateGroupInfo.h
// Sparkle
//
// Created by Mayur Pawashe on 01/24/21.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class SUHost;
@interface SUPhasedUpdateGroupInfo : NSObject
+ (NSUInteger)updateGroupForHost:(SUHost*)host;
+ (NSNumber*)setNewUpdateGroupIdentifierForHost:(SUHost*)host;
@end
NS_ASSUME_NONNULL_END
+42
View File
@@ -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
-21
View File
@@ -1,21 +0,0 @@
//
// SUSystemUpdateInfo.h
// Sparkle
//
// Created by Mayur Pawashe on 12/23/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class SUHost;
@interface SUSystemUpdateInfo : NSObject
+ (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host;
@end
NS_ASSUME_NONNULL_END
-61
View File
@@ -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
-1
View File
@@ -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"
+1
View File
@@ -12,6 +12,7 @@
<!-- The best chosen release -->
<item>
<title>Version 3.0</title>
<sparkle:phasedRolloutInterval>86400</sparkle:phasedRolloutInterval>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="3.0" length="1346234" />
<sparkle:deltas>
<enclosure url="http://localhost:1337/3.0_from_2.0.patch"
+8 -3
View File
@@ -31,6 +31,7 @@ class SUAppcastTest: XCTestCase {
XCTAssertNil(items[1].itemDescription)
XCTAssertNil(items[1].dateString)
XCTAssertFalse(items[1].isCriticalUpdate)
XCTAssertEqual(items[1].phasedRolloutInterval, 86400)
XCTAssertEqual("Version 4.0", items[2].title)
XCTAssertNil(items[2].itemDescription)
@@ -43,21 +44,25 @@ class SUAppcastTest: XCTestCase {
XCTAssertFalse(items[3].isCriticalUpdate)
// Test best appcast item & a delta update item
let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil)
let supportedAppcastItems = supportedAppcast.items!
var deltaItem: SUAppcastItem?
let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator())
let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcastItems, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator())
XCTAssertEqual(bestAppcastItem, items[1])
XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch")
// Test latest delta update item available
var latestDeltaItem: SUAppcastItem?
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator())
SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcastItems, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator())
XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch")
// Test a delta item that does not exist
var nonexistantDeltaItem: SUAppcastItem?
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator())
SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcastItems, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator())
XCTAssertNil(nonexistantDeltaItem)
} catch let err as NSError {
@@ -36,6 +36,8 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
+ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem *_Nullable __autoreleasing *_Nullable)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id<SUVersionComparison>)comparator;
+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup;
@end