Add support for phased group updates to 2.x

This commit is contained in:
Zorg committed 2021-01-24 18:14:48 -08:00
1 parent 4767ef60ec
commit 9818eff9a2
13 files changed
+148 -89

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 */,
+38 -5
View File
@@ -15,6 +15,7 @@
#import "SPUUpdaterDelegate.h"
#import "SUHost.h"
#import "SUConstants.h"
#import "SUPhasedUpdateGroupInfo.h"
#include "AppKitPrevention.h"
@@ -62,12 +63,12 @@
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 *)ac inBackground:(BOOL)background includesSkippedUpdates:(BOOL)includesSkippedUpdates
{
[self.delegate didFinishLoadingAppcast:ac];
@@ -102,7 +103,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 {
@@ -189,9 +190,41 @@
return [[self versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending;
}
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui includesSkippedUpdates:(BOOL)includesSkippedUpdates
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui inBackground:(BOOL)background includesSkippedUpdates:(BOOL)includesSkippedUpdates
{
return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && (includesSkippedUpdates || ![self itemContainsSkippedVersion:ui]);
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;
}
// Check phased group rollout for this appcast item
if (background && ![ui isCriticalUpdate]) {
NSNumber *phasedRolloutIntervalObject = [ui phasedRolloutInterval];
if (phasedRolloutIntervalObject != nil) {
NSDate* itemReleaseDate = ui.date;
if (itemReleaseDate != nil) {
NSTimeInterval timeSinceRelease = [[NSDate date] timeIntervalSinceDate:itemReleaseDate];
NSTimeInterval phasedRolloutInterval = [phasedRolloutIntervalObject doubleValue];
NSTimeInterval timeToWaitForGroup = phasedRolloutInterval * [SUPhasedUpdateGroupInfo updateGroupForHost:self.host];
if (timeSinceRelease < timeToWaitForGroup) {
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:SUAppcastAttributePhasedRolloutInterval];
}
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:SUAppcastAttributePhasedRolloutInterval];
}
}
- (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;
@@ -298,6 +317,11 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
} else if ([_installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
SULog(SULogLevelDefault, @"warning: '%@' for %@ is deprecated. Use '%@' instead.", SPUInstallationTypeInteractivePackage, SUAppcastAttributeInstallationType, SPUInstallationTypeGuidedPackage);
}
NSString* enclosureRolloutIntervalString = [enclosure objectForKey:SUAppcastAttributePhasedRolloutInterval];
if (enclosureRolloutIntervalString != nil) {
_phasedRolloutInterval = @(enclosureRolloutIntervalString.integerValue);
}
// Find the appropriate release notes URL.
NSString *releaseNotesString = [dict objectForKey:SUAppcastElementReleaseNotesLink];
+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 SUAppcastAttributePhasedRolloutInterval;
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 SUAppcastAttributePhasedRolloutInterval = @"sparkle:phasedRolloutInterval";
NSString *const SURSSAttributeURL = @"url";
NSString *const SURSSAttributeLength = @"length";
+23
View File
@@ -0,0 +1,23 @@
//
// 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*)updateGroupIdentifierForHost:(SUHost*)host;
+ (NSNumber*)setNewUpdateGroupIdentifierForHost:(SUHost*)host;
@end
NS_ASSUME_NONNULL_END
+43
View File
@@ -0,0 +1,43 @@
//
// 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"
#import "SUFileManager.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 objectForInfoDictionaryKey: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 -1
View File
@@ -12,7 +12,7 @@
<!-- The best chosen release -->
<item>
<title>Version 3.0</title>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="3.0" length="1346234" />
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="3.0" length="1346234" sparkle:phasedRolloutInterval="86400" />
<sparkle:deltas>
<enclosure url="http://localhost:1337/3.0_from_2.0.patch"
sparkle:version="3.0"
+1
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)