From 674b2238b8ef317716f645265043a21c2d649467 Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 17 Feb 2016 00:04:07 -0500 Subject: [PATCH 01/14] Make Sparkle look for the highest compatible version Sparkle's past behavior was sorting appcast items by published dates and picking the first compatible item. However, it makes more sense to pick the compatible item with the highest version (see issue #31). The NSDate instance creation & sorting has also been removed from the code. The methods we were using to parse the string into a NSDate have been deprecated, and are strongly discouraged. Namely, all methods taking an arbitrary/natural string have been nuked signaling they were probably a really bad idea. Furthermore, the date code we had created a NSCalendarDate which has been long deprecated. So we just don't handle date parsing. Even if there is a proper format for the pubDate, It is an extra burden on the developer to insert a conforming date. And we shouldn't want to rely on a potentially error-prone input field. --- Sparkle/SUAppcast.m | 20 ++++++++------------ Sparkle/SUAppcastItem.h | 2 +- Sparkle/SUAppcastItem.m | 6 +++--- Sparkle/SUBasicUpdateDriver.m | 14 +++++++++----- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 42254148..2dcc7a96 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -169,12 +169,12 @@ } else if ([name isEqualToString:SURSSElementPubDate]) { - // pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString - NSString *string = node.stringValue; - if (string) { - NSDate *date = [NSDate dateWithNaturalLanguageString:string]; - if (date) - dict[name] = date; + // We don't want to parse and create a NSDate instance - + // that's a risk we can avoid. We don't use the date anywhere other + // than it being accessible from SUAppcastItem + NSString *dateString = node.stringValue; + if (dateString) { + dict[name] = dateString; } } else if ([name isEqualToString:SUAppcastElementDeltas]) @@ -221,12 +221,8 @@ [dict removeAllObjects]; } } - - if ([appcastItems count]) { - NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; - [appcastItems sortUsingDescriptors:@[sort]]; - self.items = appcastItems; - } + + self.items = appcastItems; if (failed) { [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while parsing the update feed.", nil) }]]; diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 86843bfb..47b6ee48 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -14,7 +14,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *title; -@property (copy, readonly) NSDate *date; +@property (copy, readonly) NSString *dateString; @property (copy, readonly) NSString *itemDescription; @property (strong, readonly) NSURL *releaseNotesURL; @property (copy, readonly) NSString *DSASignature; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 7ee42020..e43f3574 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -16,7 +16,7 @@ @interface SUAppcastItem () @property (copy, readwrite) NSString *title; -@property (copy, readwrite) NSDate *date; +@property (copy, readwrite) NSString *dateString; @property (copy, readwrite) NSString *itemDescription; @property (strong, readwrite) NSURL *releaseNotesURL; @property (copy, readwrite) NSString *DSASignature; @@ -31,7 +31,7 @@ @end @implementation SUAppcastItem -@synthesize date; +@synthesize dateString; @synthesize deltaUpdates; @synthesize displayVersionString; @synthesize DSASignature; @@ -104,7 +104,7 @@ propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict]; self.title = dict[SURSSElementTitle]; - self.date = dict[SURSSElementPubDate]; + self.dateString = dict[SURSSElementPubDate]; self.itemDescription = dict[SURSSElementDescription]; NSString *theInfoURL = dict[SURSSElementLink]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 4ab61093..bb92274a 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -136,11 +136,15 @@ } else // If not, we'll take care of it ourselves. { - // Find the first update we can actually use. - NSEnumerator *updateEnumerator = [[ac items] objectEnumerator]; - do { - item = [updateEnumerator nextObject]; - } while (item && ![self hostSupportsItem:item]); + // Find the best supported update + id comparator = [self versionComparator]; + for(SUAppcastItem *candidate in ac.items) { + if ([self hostSupportsItem:candidate]) { + if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { + item = candidate; + } + } + } SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]]; if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) { From 8a04cc726f86dfb8a8aaf7eb54eca91c30e9545c Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 19 Feb 2016 10:19:00 -0500 Subject: [PATCH 02/14] Appcast items are no longer sorted; reflect that in unit tests --- Tests/SUAppcastTest.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 5f39f795..b60478f9 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -21,11 +21,13 @@ class SUAppcastTest: XCTestCase { let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem]; XCTAssertEqual(2, items.count); - XCTAssertEqual("Version 3.0", items[0].title); - XCTAssertNil(items[0].itemDescription); - XCTAssertEqual("Version 2.0", items[1].title); - XCTAssertEqual("desc", items[1].itemDescription); + XCTAssertEqual("Version 2.0", items[0].title); + XCTAssertEqual("desc", items[0].itemDescription); + + XCTAssertEqual("Version 3.0", items[1].title); + XCTAssertNil(items[1].itemDescription); + } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); From 004ac3f9ae88012e06c6cc092f5a8b4635c78374 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 19 Feb 2016 11:26:35 -0500 Subject: [PATCH 03/14] Test the best chosen appcast item --- Sparkle/SUBasicUpdateDriver.h | 2 +- Sparkle/SUBasicUpdateDriver.m | 32 +++++++++++++--------- Sparkle/SUUserInitiatedUpdateDriver.m | 2 +- Tests/Resources/testappcast.xml | 15 ++++++++++ Tests/SUAppcastTest.swift | 12 +++++++- Tests/Sparkle Unit Tests-Bridging-Header.h | 9 ++++++ 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index 8c6960d8..301b4bc5 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -24,7 +24,7 @@ - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (BOOL)isItemNewer:(SUAppcastItem *)ui; -- (BOOL)hostSupportsItem:(SUAppcastItem *)ui; ++ (BOOL)hostSupportsItem:(SUAppcastItem *)ui; - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui; - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui; - (void)appcastDidFinishLoading:(SUAppcast *)ac; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index f6cf84b7..1362a57e 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -82,12 +82,20 @@ return comparator; } -- (BOOL)isItemNewer:(SUAppcastItem *)ui ++ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator { - return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending; + 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; + } + } + } + return item; } -- (BOOL)hostSupportsItem:(SUAppcastItem *)ui ++ (BOOL)hostSupportsItem:(SUAppcastItem *)ui { if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; } @@ -106,6 +114,11 @@ return minimumVersionOK && maximumVersionOK; } +- (BOOL)isItemNewer:(SUAppcastItem *)ui +{ + return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending; +} + - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui { NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey]; @@ -115,7 +128,7 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui { - return ui && [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui]; + return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui]; } - (void)appcastDidFinishLoading:(SUAppcast *)ac @@ -140,18 +153,11 @@ else // If not, we'll take care of it ourselves. { // Find the best supported update - id comparator = [self versionComparator]; - for(SUAppcastItem *candidate in ac.items) { - if ([self hostSupportsItem:candidate]) { - if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { - item = candidate; - } - } - } + item = [[self class] bestAppcastItemFromAppcastItems:ac.items withComparator:[self versionComparator]]; if (item) { SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]]; - if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) { + if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { self.nonDeltaUpdateItem = item; item = deltaUpdateItem; } diff --git a/Sparkle/SUUserInitiatedUpdateDriver.m b/Sparkle/SUUserInitiatedUpdateDriver.m index d1e0c9a6..04e96b23 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.m +++ b/Sparkle/SUUserInitiatedUpdateDriver.m @@ -81,7 +81,7 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui { // We don't check to see if this update's been skipped, because the user explicitly *asked* if he had the latest version. - return [self hostSupportsItem:ui] && [self isItemNewer:ui]; + return [[self class] hostSupportsItem:ui] && [self isItemNewer:ui]; } @end diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index 0023508e..b88eb16b 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -8,10 +8,25 @@ Sat, 26 Jul 2014 15:20:11 +0000 + Version 3.0 Sat, 26 Jul 2014 15:20:12 +0000 + + + Version 4.0 + Sat, 26 Jul 2014 15:20:13 +0000 + + 17.0.0 + + + + Version 5.0 + Sat, 26 Jul 2014 15:20:14 +0000 + + 2.0.0 + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index b60478f9..72d55639 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -20,14 +20,24 @@ class SUAppcastTest: XCTestCase { do { let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem]; - XCTAssertEqual(2, items.count); + XCTAssertEqual(4, items.count); XCTAssertEqual("Version 2.0", items[0].title); XCTAssertEqual("desc", items[0].itemDescription); + // This is the best release matching our system version XCTAssertEqual("Version 3.0", items[1].title); XCTAssertNil(items[1].itemDescription); + XCTAssertEqual("Version 4.0", items[2].title); + XCTAssertNil(items[2].itemDescription); + + XCTAssertEqual("Version 5.0", items[3].title); + XCTAssertNil(items[3].itemDescription); + + let bestAppcastItem = SUBasicUpdateDriver.bestAppcastItemFromAppcastItems(items, withComparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertEqual(bestAppcastItem, items[1]) } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 512f4a58..8794e12b 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -8,6 +8,9 @@ #import "SUFileManager.h" #import "SUAppcast.h" #import "SUAppcastItem.h" +#import "SUBasicUpdateDriver.h" +#import "SUVersionComparisonProtocol.h" +#import "SUStandardVersionComparator.h" // Duplicated to avoid exporting a private symbol from SUFileManager static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @@ -23,6 +26,12 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @end +@interface SUBasicUpdateDriver (Private) + ++ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator; + +@end + @interface SUAppcast (Private) - (NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp; From 2a3e88bf96030e8584647055ee113af9fa3c548d Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 19 Feb 2016 11:45:54 -0500 Subject: [PATCH 04/14] Test the dateString field --- Tests/Resources/testappcast.xml | 2 -- Tests/SUAppcastTest.swift | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index b88eb16b..18a256ac 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -11,7 +11,6 @@ Version 3.0 - Sat, 26 Jul 2014 15:20:12 +0000 @@ -24,7 +23,6 @@ Version 5.0 - Sat, 26 Jul 2014 15:20:14 +0000 2.0.0 diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 72d55639..097cf95b 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -24,16 +24,20 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual("Version 2.0", items[0].title); XCTAssertEqual("desc", items[0].itemDescription); + XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString) // This is the best release matching our system version XCTAssertEqual("Version 3.0", items[1].title); XCTAssertNil(items[1].itemDescription); + XCTAssertNil(items[1].dateString) XCTAssertEqual("Version 4.0", items[2].title); XCTAssertNil(items[2].itemDescription); + XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString) XCTAssertEqual("Version 5.0", items[3].title); XCTAssertNil(items[3].itemDescription); + XCTAssertNil(items[3].dateString) let bestAppcastItem = SUBasicUpdateDriver.bestAppcastItemFromAppcastItems(items, withComparator: SUStandardVersionComparator.defaultComparator()) From b9c664687dd720cf6ec0f9ea3925bbc65e6a3841 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 19 Feb 2016 12:43:41 -0500 Subject: [PATCH 05/14] Take delta updates in account and add tests for them --- Sparkle/SUBasicUpdateDriver.m | 24 ++++++++++++++-------- Tests/Resources/testappcast.xml | 15 ++++++++++++++ Tests/SUAppcastTest.swift | 19 +++++++++++++++-- Tests/Sparkle Unit Tests-Bridging-Header.h | 2 +- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 1362a57e..51ea4896 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -82,7 +82,7 @@ return comparator; } -+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { SUAppcastItem *item = nil; for(SUAppcastItem *candidate in appcastItems) { @@ -92,6 +92,14 @@ } } } + + if (item && deltaItem) { + SUAppcastItem *deltaUpdateItem = [item deltaUpdates][hostVersion]; + if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { + *deltaItem = deltaUpdateItem; + } + } + return item; } @@ -153,14 +161,12 @@ else // If not, we'll take care of it ourselves. { // Find the best supported update - item = [[self class] bestAppcastItemFromAppcastItems:ac.items withComparator:[self versionComparator]]; - - if (item) { - SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]]; - if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { - self.nonDeltaUpdateItem = item; - item = deltaUpdateItem; - } + SUAppcastItem *deltaUpdateItem = nil; + item = [[self class] bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; + + if (item && deltaUpdateItem) { + self.nonDeltaUpdateItem = item; + item = deltaUpdateItem; } } diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index 18a256ac..e3894b41 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -12,6 +12,21 @@ Version 3.0 + + + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 097cf95b..14fa2978 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -39,9 +39,24 @@ class SUAppcastTest: XCTestCase { XCTAssertNil(items[3].itemDescription); XCTAssertNil(items[3].dateString) - let bestAppcastItem = SUBasicUpdateDriver.bestAppcastItemFromAppcastItems(items, withComparator: SUStandardVersionComparator.defaultComparator()) - + // Test best appcast item & a delta update item + var deltaItem: SUAppcastItem? = nil + let bestAppcastItem = SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.defaultComparator()) + XCTAssertEqual(bestAppcastItem, items[1]) + XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch") + + // Test latest delta update item available + var latestDeltaItem: SUAppcastItem? = nil + SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch") + + // Test a delta item that does not exist + var nonexistantDeltaItem: SUAppcastItem? = nil + SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertNil(nonexistantDeltaItem) } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 8794e12b..d08dafb8 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -28,7 +28,7 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @interface SUBasicUpdateDriver (Private) -+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator; ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator; @end From d0adc0af39143658e76dfeffff7fb993c7fb289b Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 28 Feb 2016 14:06:05 -0500 Subject: [PATCH 06/14] Fix code signing verifier tests when ran locally The tests sometimes fail for me when copying these files over, because they already may exist. I guess they're not torn down properly. --- Tests/SUCodeSigningVerifierTest.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index 95e394f0..a2b7e764 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -69,6 +69,10 @@ NSError *error = nil; NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent]; NSString *signedAndValid = [tempDir stringByAppendingPathComponent:@"valid-signed.app"]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndValid]) { + [[NSFileManager defaultManager] removeItemAtPath:signedAndValid error:NULL]; + } if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) { self.validSignedAppPath = signedAndValid; if (![self codesignAppPath:self.validSignedAppPath]) { @@ -85,6 +89,10 @@ NSError *error = nil; NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent]; NSString *signedAndInvalid = [tempDir stringByAppendingPathComponent:@"invalid-signed.app"]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndInvalid]) { + [[NSFileManager defaultManager] removeItemAtPath:signedAndInvalid error:NULL]; + } if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndInvalid error:&error]) { self.invalidSignedAppPath = signedAndInvalid; if ([self codesignAppPath:self.invalidSignedAppPath]) { From cd3d7d9f98076faa6602811d2fc366cd68ff370c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Tue, 8 Mar 2016 23:23:41 +0000 Subject: [PATCH 07/14] Fix #776 --- Sparkle/SUFileManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index be5ef09b..725e78ac 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -267,7 +267,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { // root-level symbolic link. NSString *rootURLPath = rootURL.path; NSDictionary *rootAttributes = [_fileManager attributesOfItemAtPath:rootURLPath error:nil]; - NSString *rootType = rootAttributes[NSFileType]; + NSString *rootType = [rootAttributes objectForKey:NSFileType]; // 10.7 can't subscript this if ([rootType isEqualToString:NSFileTypeDirectory]) { // The NSDirectoryEnumerator will avoid recursing into any contained From 28e8a1fdafa3b8c2c1879c10c2c0d315e358cddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Wed, 9 Mar 2016 00:09:04 +0000 Subject: [PATCH 08/14] More workarounds for OS X 10.7 #776 --- Sparkle/SUBinaryDeltaCommon.m | 4 ++-- Sparkle/SUFileManager.m | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index be3966ce..de247ee5 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -231,12 +231,12 @@ BOOL modifyPermissions(NSString *path, mode_t desiredPermissions) if (!attributes) { return NO; } - NSNumber *permissions = attributes[NSFilePosixPermissions]; + NSNumber *permissions = [attributes objectForKey:NSFilePosixPermissions]; if (!permissions) { return NO; } mode_t newMode = ([permissions unsignedShortValue] & ~PERMISSION_FLAGS) | desiredPermissions; - int (*changeModeFunc)(const char *, mode_t) = [attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod; + int (*changeModeFunc)(const char *, mode_t) = [[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod; if (changeModeFunc([path fileSystemRepresentation], newMode) != 0) { return NO; } diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 725e78ac..d0fc3b00 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -151,7 +151,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } if (isDirectory != NULL) { - *isDirectory = [attributes[NSFileType] isEqualToString:NSFileTypeDirectory]; + *isDirectory = [[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory]; } return YES; @@ -595,7 +595,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *ownerID = matchFileAttributes[NSFileOwnerAccountID]; + NSNumber *ownerID = [matchFileAttributes objectForKey:NSFileOwnerAccountID]; if (ownerID == nil) { // shouldn't be possible to error here, but just in case if (error != NULL) { @@ -604,7 +604,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *groupID = matchFileAttributes[NSFileGroupOwnerAccountID]; + NSNumber *groupID = [matchFileAttributes objectForKey:NSFileGroupOwnerAccountID]; if (groupID == nil) { // shouldn't be possible to error here, but just in case if (error != NULL) { @@ -613,8 +613,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *targetOwnerID = targetFileAttributes[NSFileOwnerAccountID]; - NSNumber *targetGroupID = targetFileAttributes[NSFileGroupOwnerAccountID]; + NSNumber *targetOwnerID = [targetFileAttributes objectForKey:NSFileOwnerAccountID]; + NSNumber *targetGroupID = [targetFileAttributes objectForKey:NSFileGroupOwnerAccountID]; if ((targetOwnerID != nil && [ownerID isEqualToNumber:targetOwnerID]) && (targetGroupID != nil && [groupID isEqualToNumber:targetGroupID])) { // Assume they're the same even if we don't check every file recursively From 317423ae78aaa7ee62ed29ad7624522d8743f5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Wed, 9 Mar 2016 00:33:59 +0000 Subject: [PATCH 09/14] One more attr fix #776 --- Sparkle/SUPipedUnarchiver.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 7317143d..dc0b5192 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -62,7 +62,8 @@ SULog(@"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination); // Get the file size. - NSUInteger expectedLength = [[[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil][NSFileSize] unsignedIntegerValue]; + NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil]; + NSUInteger expectedLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue]; if (expectedLength > 0) { NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath]; From 34a78d59fc65d113512637e2f02c1ea61236aa0e Mon Sep 17 00:00:00 2001 From: kleuter Date: Wed, 9 Mar 2016 12:07:51 +0100 Subject: [PATCH 10/14] Fixed crash on 10.7 - subscript operator not available https://github.com/sparkle-project/Sparkle/issues/776 related --- Sparkle/SUOperatingSystem.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index 85c18ebc..d9f1e90a 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -20,10 +20,11 @@ { NSOperatingSystemVersion version = { 0, 0, 0 }; NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; - NSArray *components = [[NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]][@"ProductVersion"] componentsSeparatedByString:@"."]; - version.majorVersion = components.count > 0 ? [components[0] integerValue] : 0; - version.minorVersion = components.count > 1 ? [components[1] integerValue] : 0; - version.patchVersion = components.count > 2 ? [components[2] integerValue] : 0; + NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]]; + NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; + version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; + version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; + version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; return version; } #endif From 77511c8f196ebd99a007524a1dd0c4fefaae8ef7 Mon Sep 17 00:00:00 2001 From: kleuter Date: Wed, 9 Mar 2016 12:07:51 +0100 Subject: [PATCH 11/14] Fixed crash on 10.7 - subscript operator not available https://github.com/sparkle-project/Sparkle/issues/776 related --- Sparkle/SUOperatingSystem.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index 85c18ebc..d9f1e90a 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -20,10 +20,11 @@ { NSOperatingSystemVersion version = { 0, 0, 0 }; NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; - NSArray *components = [[NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]][@"ProductVersion"] componentsSeparatedByString:@"."]; - version.majorVersion = components.count > 0 ? [components[0] integerValue] : 0; - version.minorVersion = components.count > 1 ? [components[1] integerValue] : 0; - version.patchVersion = components.count > 2 ? [components[2] integerValue] : 0; + NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]]; + NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; + version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; + version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; + version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; return version; } #endif From 1c8d54166b7829ec12dc659983c66be2b347d98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Fri, 11 Mar 2016 09:11:12 +0000 Subject: [PATCH 12/14] v1.14.0 --- CHANGELOG | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b514cb8d..d730c9db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,15 +1,17 @@ -# 1.14.0 +# 1.14.0 (Mar 11, 2016) +* Disable javascript by default and make it opt-in (Zorg) * URL-encoding of appcast URLs is preserved (Kornel Lesiński) * Delegate is asked for fallback updates if delta update fails (Kornel Lesiński) +* Fixed crash on 10.7 - subscript operator not available (kleuter) * Fixed check of feed URL before delegate had a chance to set it (Kornel Lesiński) * Re-added support for password-protected dmg images (Andrew K. Boyd) * Added warning about ATS blocking (Kornel Lesiński) * Translation fixes for pt-BR. (vitu) * Add some Japanese lozalized strings (1024jp) * Made test app available in all languages #695 (LIU Dongyuan / 柳东原) -* Removed a test resource from the framework bundle (Karl Moskowski) * Czech localizations update (Frantisek Erben) +* Removed a test resource from the framework bundle (Karl Moskowski) * Test if the updated app is the frontmost one (Zorg) * UI Tests for the Test Application (Zorg) From 698e737b565365b006c9bcd0406907b24321dd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Sat, 12 Mar 2016 01:16:51 +0000 Subject: [PATCH 13/14] CocoaPods --- Makefile | 2 ++ Sparkle.podspec | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f46efad9..f27e6e8c 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ localizable-strings: release: xcodebuild -scheme Distribution -configuration Release -derivedDataPath "$(BUILDDIR)" build open -R "$(BUILDDIR)/Build/Products/Release/Sparkle-"*.tar.bz2 + cat Sparkle.podspec + @echo "Don't forget to update CocoaPods!" build: xcodebuild clean build diff --git a/Sparkle.podspec b/Sparkle.podspec index 889a31e7..e895c250 100644 --- a/Sparkle.podspec +++ b/Sparkle.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sparkle" - s.version = "1.13.1" + s.version = "1.14.0" s.summary = "A software update framework for OS X" s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers." s.homepage = "http://sparkle-project.org" From 013e60204dd49e899eb7b9418771d586aa7f8967 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 13 Mar 2016 23:40:23 -0400 Subject: [PATCH 14/14] Don't use subscripting where it may potentially be risky on 10.7 --- Sparkle/Autoupdate/Autoupdate.m | 12 ++++++------ Sparkle/SUAppcast.m | 4 ++-- Sparkle/SUHost.m | 2 +- Sparkle/SUSystemProfiler.m | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index ddc60f6c..51b9619a 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -247,16 +247,16 @@ int main(int __unused argc, const char __unused *argv[]) NSApplication *application = [NSApplication sharedApplication]; - BOOL shouldShowUI = (args.count > 6) ? [args[6] boolValue] : YES; + BOOL shouldShowUI = (args.count > 6) ? [[args objectAtIndex:6] boolValue] : YES; if (shouldShowUI) { [application activateIgnoringOtherApps:YES]; } - AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:args[1] - relaunchPath:args[2] - parentProcessId:[args[3] intValue] - updateFolderPath:args[4] - shouldRelaunch:(args.count > 5) ? [args[5] boolValue] : YES + AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:[args objectAtIndex:1] + relaunchPath:[args objectAtIndex:2] + parentProcessId:[[args objectAtIndex:3] intValue] + updateFolderPath:[args objectAtIndex:4] + shouldRelaunch:(args.count > 5) ? [[args objectAtIndex:5] boolValue] : YES shouldShowUI:shouldShowUI]; [application setDelegate:appInstaller]; [application run]; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 54b1d2b7..05cba1cd 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -248,9 +248,9 @@ NSUnderlyingErrorKey: error, }]; - NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey]; + NSURL *failingUrl = [error.userInfo objectForKey:NSURLErrorFailingURLErrorKey]; if (failingUrl) { - userInfo[NSURLErrorFailingURLErrorKey] = failingUrl; + [userInfo setObject:failingUrl forKey:NSURLErrorFailingURLErrorKey]; } self.completionBlock([NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:userInfo]); diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index c49ba368..00ba50d1 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -79,7 +79,7 @@ NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachePath = nil; if ([cachePaths count]) { - cachePath = cachePaths[0]; + cachePath = [cachePaths objectAtIndex:0]; } if (!cachePath) { SULog(@"Failed to find user's cache directory! Using system default"); diff --git a/Sparkle/SUSystemProfiler.m b/Sparkle/SUSystemProfiler.m index 230c808f..4071da6b 100644 --- a/Sparkle/SUSystemProfiler.m +++ b/Sparkle/SUSystemProfiler.m @@ -115,7 +115,7 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0); if (error == 0) { NSString *rawModelName = @(cpuModel); - NSString *visibleModelName = modelTranslation[rawModelName]; + NSString *visibleModelName = [modelTranslation objectForKey:rawModelName]; if (visibleModelName == nil) { visibleModelName = rawModelName; } @@ -135,7 +135,7 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defs objectForKey:@"AppleLanguages"]; if ([languages count] > 0) { - [profileArray addObject:[NSDictionary dictionaryWithObjects:@[SUSystemProfilerPreferredLanguageKey, @"Preferred Language", languages[0], languages[0]] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[SUSystemProfilerPreferredLanguageKey, @"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0]] forKeys:profileDictKeys]]; } // Application sending the request