Handle installer cleanup occur after any stage

This commit is contained in:
Zorg committed 2016-03-13 13:39:28 -04:00
1 parent b10202769f
commit f82a698937
2 files changed
+32 -8

No files matched your search

+18 -2
View File
@@ -318,6 +318,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
NSError *firstStageError = nil;
if (![installer performFirstStage:&firstStageError]) {
SULog(@"Error: Failed to start installer with error: %@", firstStageError);
[self.installer cleanup];
self.installer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE];
});
@@ -357,6 +360,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
NSError *secondStageError = nil;
if (![self.installer performSecondStageAllowingUI:self.shouldShowUI error:&secondStageError]) {
SULog(@"Error: Failed to resume installer on stage 2 with error: %@", secondStageError);
[self.installer cleanup];
self.installer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE];
});
@@ -390,7 +396,12 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
if (!success) {
SULog(@"Timed out waiting for target to terminate. Target path is %@", self.host.bundlePath);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self.installer cleanup];
self.installer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE];
});
return;
}
@@ -400,7 +411,12 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
NSError *thirdStageError = nil;
if (![self.installer performThirdStage:&thirdStageError]) {
SULog(@"Failed to finalize installation with error: %@", thirdStageError);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self.installer cleanup];
self.installer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE];
});
return;
}
+14 -6
View File
@@ -265,15 +265,23 @@
NSURL *tempOldDirectoryURL = self.tempOldDirectoryURL;
NSURL *tempNewDirectoryURL = self.tempNewDirectoryURL;
// Cleanup: move the old app to the trash
NSError *trashError = nil;
if (![fileManager moveItemAtURLToTrash:oldTempURL error:&trashError]) {
SULog(@"Failed to move %@ to trash with error %@", oldTempURL, trashError);
// Note: I'm intentionally not checking if an item at the file URLs exist since these methods already do that for us
if (oldTempURL != nil) {
// Cleanup: move the old app to the trash
NSError *trashError = nil;
if (![fileManager moveItemAtURLToTrash:oldTempURL error:&trashError]) {
SULog(@"Failed to move %@ to trash with error %@", oldTempURL, trashError);
}
}
[fileManager removeItemAtURL:tempOldDirectoryURL error:NULL];
if (tempOldDirectoryURL != nil) {
[fileManager removeItemAtURL:tempOldDirectoryURL error:NULL];
}
[fileManager removeItemAtURL:tempNewDirectoryURL error:NULL];
if (tempNewDirectoryURL != nil) {
[fileManager removeItemAtURL:tempNewDirectoryURL error:NULL];
}
}
@end