Skip to content

Commit

Permalink
Merge pull request #1084 from ksuther/nil-progress-block
Browse files Browse the repository at this point in the history
Don't assume that the progress block exists (the parameter is nullable)
  • Loading branch information
kornelski committed Jun 2, 2017
2 parents 61774b3 + d0a6c69 commit cbeaeb2
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions Sparkle/SUPlainInstaller.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(1/10.0);
if (progress) {
progress(1/10.0);
}

SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:fileOperationToolPath];

Expand All @@ -85,7 +87,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(2/10.0);
if (progress) {
progress(2/10.0);
}

// Move the new app to our temporary directory
NSString *newURLLastPathComponent = newURL.lastPathComponent;
Expand All @@ -96,7 +100,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(3/10.0);
if (progress) {
progress(3/10.0);
}

// Release our new app from quarantine, fix its owner and group IDs, and update its modification time while it's at our temporary destination
// We must leave moving the app to its destination as the final step in installing it, so that
Expand All @@ -108,7 +114,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
SULog(SULogLevelError, @"Failed to release quarantine at %@ with error %@", newTempURL.path, quarantineError);
}

progress(4/10.0);
if (progress) {
progress(4/10.0);
}

NSURL *oldURL = [NSURL fileURLWithPath:host.bundlePath];
if (oldURL == nil) {
Expand All @@ -127,15 +135,18 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}


progress(5/10.0);
if (progress) {
progress(5/10.0);
}

if (![fileManager updateModificationAndAccessTimeOfItemAtURL:newTempURL error:error]) {
// Not a fatal error, but a pretty unfortunate one
SULog(SULogLevelError, @"Failed to update modification and access time of new app at %@", newTempURL.path);
}

progress(6/10.0);
if (progress) {
progress(6/10.0);
}

// Decide on a destination name we should use for the older app when we move it around the file system
NSString *oldDestinationName = nil;
Expand All @@ -159,7 +170,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(7/10.0);
if (progress) {
progress(7/10.0);
}

// Move the old app to the temporary directory
NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldDestinationNameWithPathExtension];
Expand All @@ -173,7 +186,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(8/10.0);
if (progress) {
progress(8/10.0);
}

// Move the new app to its final destination
if (![fileManager moveItemAtURL:newTempURL toURL:installationURL error:error]) {
Expand All @@ -189,7 +204,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
return NO;
}

progress(9/10.0);
if (progress) {
progress(9/10.0);
}

// From here on out, we don't really need to bring up authorization if we haven't done so prior
SUFileManager *constrainedFileManager = [fileManager fileManagerByPreservingAuthorizationRights];
Expand All @@ -198,7 +215,9 @@ - (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL
[constrainedFileManager removeItemAtURL:tempOldDirectoryURL error:NULL];
[constrainedFileManager removeItemAtURL:tempNewDirectoryURL error:NULL];

progress(10/10.0);
if (progress) {
progress(10/10.0);
}

return YES;
}
Expand Down

0 comments on commit cbeaeb2

Please sign in to comment.