Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions Sparkle/SPUCoreBasedUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -247,18 +248,25 @@ - (void)extractUpdate:(SPUDownloadedUpdate *)downloadedUpdate

- (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
Expand Down Expand Up @@ -335,22 +343,27 @@ - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
[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;

[self downloadUpdateFromAppcastItem:secondaryUpdateItem secondaryAppcastItem:nil inBackground:backgroundDownload];
}

- (void)installerDidFailToApplyDeltaUpdate
{
[self clearDownloadedUpdate];

[self fallBackAndDownloadRegularUpdate];
}

- (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately error:(nullable NSError *)error
{
[self.installerDriver abortInstall];
Expand Down
7 changes: 6 additions & 1 deletion Sparkle/SUAppcastDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ - (SUAppcastItem *)retrieveBestAppcastItemFromAppcast:(SUAppcast *)appcast versi
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..
Expand Down Expand Up @@ -281,6 +280,12 @@ + (SUAppcast *)filterAppcast:(SUAppcast *)appcast forMacOSAndAllowedChannels:(NS
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
Expand Down
6 changes: 6 additions & 0 deletions Tests/Resources/testappcast_channels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion Tests/SUAppcastTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down