Skip to content

Commit

Permalink
Don't error if our conditional GET fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Jun 14, 2016
1 parent 9ebfd39 commit d92d385
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Squirrel/SQRLUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,27 @@ - (RACSignal *)downloadAndPrepareUpdate:(SQRLUpdate *)update {
return [[[self
uniqueTemporaryDirectoryForUpdate]
flattenMap:^(NSURL *downloadDirectory) {
void (^cleanUp)(void) = ^{
NSError *error;
if (![NSFileManager.defaultManager removeItemAtURL:downloadDirectory error:&error]) {
NSLog(@"Error removing temporary download directory at %@: %@", downloadDirectory, error.sqrl_verboseDescription);
}
};

return [[[self
downloadBundleForUpdate:update intoDirectory:downloadDirectory]
flattenMap:^(NSBundle *updateBundle) {
// If the bundle is nil it means our conditional GET told us
// we already downloaded the update. So just clean up.
if (updateBundle == nil) {
cleanUp();
return [RACSignal empty];
}

return [self verifyAndPrepareUpdate:update fromBundle:updateBundle];
}]
doError:^(id _) {
NSError *error = nil;
if (![NSFileManager.defaultManager removeItemAtURL:downloadDirectory error:&error]) {
NSLog(@"Error removing temporary download directory at %@: %@", downloadDirectory, error.sqrl_verboseDescription);
}
cleanUp();
}];
}]
setNameWithFormat:@"%@ -downloadAndPrepareUpdate: %@", self, update];
Expand All @@ -339,7 +350,7 @@ - (RACSignal *)downloadBundleForUpdate:(SQRLUpdate *)update intoDirectory:(NSURL
NSHTTPURLResponse *httpResponse = (id)response;

if (httpResponse.statusCode == 304 /* Not Modified */) {
return [RACSignal empty];
return [RACSignal return:nil];
}

if (!(httpResponse.statusCode >= 200 && httpResponse.statusCode <= 299)) {
Expand All @@ -359,6 +370,8 @@ - (RACSignal *)downloadBundleForUpdate:(SQRLUpdate *)update intoDirectory:(NSURL
}]
flatten]
flattenMap:^(NSData *data) {
if (data == nil) return [RACSignal return:nil];

NSURL *zipOutputURL = [downloadDirectory URLByAppendingPathComponent:zipDownloadURL.lastPathComponent];

NSError *error = nil;
Expand All @@ -370,19 +383,27 @@ - (RACSignal *)downloadBundleForUpdate:(SQRLUpdate *)update intoDirectory:(NSURL
}];
}]
doNext:^(NSURL *zipOutputURL) {
if (zipOutputURL == nil) return;

NSLog(@"Download completed to: %@", zipOutputURL);
}]
flattenMap:^(NSURL *zipOutputURL) {
return [[SQRLZipArchiver
if (zipOutputURL == nil) return [RACSignal return:nil];

return [[[[SQRLZipArchiver
unzipArchiveAtURL:zipOutputURL intoDirectoryAtURL:downloadDirectory]
ignoreValues]
concat:[RACSignal return:zipOutputURL]]
doCompleted:^{
NSError *error = nil;
if (![NSFileManager.defaultManager removeItemAtURL:zipOutputURL error:&error]) {
NSLog(@"Error removing downloaded archive at %@: %@", zipOutputURL, error.sqrl_verboseDescription);
}
}];
}]
then:^{
flattenMap:^(NSURL *zipOutputURL) {
if (zipOutputURL == nil) return [RACSignal return:nil];

return [self updateBundleMatchingCurrentApplicationInDirectory:downloadDirectory];
}]
setNameWithFormat:@"%@ -downloadBundleForUpdate: %@ intoDirectory: %@", self, update, downloadDirectory];
Expand Down

0 comments on commit d92d385

Please sign in to comment.