Fall back to regular update if delta update fails to download (#2118)

Also log out the download failure when a delta update fails to download (such as a 404 error for example).

Additionally, add a check to make sure that top-level appcast items cannot be delta update items.
This commit is contained in:
Zorg authored and GitHub committed 2022-05-01 22:58:29 -07:00
1 parent 180f8975cf
commit 9042c8dbd9
4 files changed
+38 -14

No files matched your search

+25 -12
View File
@@ -13,6 +13,7 @@
#import "SPUInstallerDriver.h"
#import "SPUDownloadDriver.h"
#import "SULog.h"
#import "SULog+NSError.h"
#import "SUErrors.h"
#import "SPUResumableUpdate.h"
#import "SPUDownloadedUpdate.h"
@@ -247,18 +248,25 @@
- (void)downloadDriverDidFailToDownloadFileWithError:(NSError *)error
{
if ([self.updaterDelegate respondsToSelector:@selector((updater:failedToDownloadUpdate:error:))]) {
NSError *errorToReport = [error.userInfo objectForKey:NSUnderlyingErrorKey];
if (errorToReport == nil) {
errorToReport = error;
if ([self.updateItem isDeltaUpdate]) {
SULog(SULogLevelError, @"Failed to download delta update. Falling back to regular update...");
SULogError(error);
[self fallBackAndDownloadRegularUpdate];
} else {
if ([self.updaterDelegate respondsToSelector:@selector((updater:failedToDownloadUpdate:error:))]) {
NSError *errorToReport = [error.userInfo objectForKey:NSUnderlyingErrorKey];
if (errorToReport == nil) {
errorToReport = error;
}
[self.updaterDelegate updater:self.updater
failedToDownloadUpdate:self.updateItem
error:errorToReport];
}
[self.updaterDelegate updater:self.updater
failedToDownloadUpdate:self.updateItem
error:errorToReport];
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
}
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
}
- (void)installerDidStartInstallingWithApplicationTerminated:(BOOL)applicationTerminated
@@ -335,15 +343,13 @@
[self.delegate basicDriverIsRequestingAbortUpdateWithError:error];
}
- (void)installerDidFailToApplyDeltaUpdate
- (void)fallBackAndDownloadRegularUpdate
{
SUAppcastItem *secondaryUpdateItem = self.secondaryUpdateItem;
assert(secondaryUpdateItem != nil);
BOOL backgroundDownload = self.downloadDriver.inBackground;
[self clearDownloadedUpdate];
// Fall back to the non-delta update. Note that we don't want to trigger another update was found event.
self.updateItem = secondaryUpdateItem;
self.secondaryUpdateItem = nil;
@@ -351,6 +357,13 @@
[self downloadUpdateFromAppcastItem:secondaryUpdateItem secondaryAppcastItem:nil inBackground:backgroundDownload];
}
- (void)installerDidFailToApplyDeltaUpdate
{
[self clearDownloadedUpdate];
[self fallBackAndDownloadRegularUpdate];
}
- (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately error:(nullable NSError *)error
{
[self.installerDriver abortInstall];
+6 -1
View File
@@ -168,7 +168,6 @@
regularItemFromDelegate = nil;
delegateOptedOutOfSelection = NO;
} else {
assert(!candidateItem.deltaUpdate);
if (candidateItem.deltaUpdate) {
// Client would have to go out of their way to examine the .deltaUpdates to return one
// We need them to give us a regular update item back instead..
@@ -281,6 +280,12 @@
return NO;
}
// Delta updates cannot be top-level entries
BOOL isDeltaUpdate = [item isDeltaUpdate];
if (isDeltaUpdate) {
return NO;
}
NSString *channel = item.channel;
if (channel == nil) {
// Item is on the default channel
+6
View File
@@ -54,5 +54,11 @@
<sparkle:version>6.0</sparkle:version>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" sparkle:os="windows" />
</item>
<!-- An invalid release with top level delta item -->
<item>
<title>Version 7.0</title>
<sparkle:version>7.0</sparkle:version>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" sparkle:deltaFrom="5.0" sparkle:edSignature="..." />
</item>
</channel>
</rss>
+1 -1
View File
@@ -91,7 +91,7 @@ class SUAppcastTest: XCTestCase {
let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator)
let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver)
XCTAssertEqual(5, appcast.items.count)
XCTAssertEqual(6, appcast.items.count)
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["beta", "nightly"])