diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 1f89fdf5..36bc7455 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -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; } diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 075dc03b..65407922 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -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