Merging in David Smith's branch to fix bug #230123. We now copy the relaunch tool out of the host before installing the update; that way, we can use the old version's tool. This insures us against future changes in the relaunch method.

This commit is contained in:
Andy Matuschak committed 2008-05-15 10:58:49 -07:00
commit 6d8f5be18c
5 files changed
+27 -6

No files matched your search

+3 -1
View File
@@ -46,10 +46,12 @@
}
}
- (BOOL)shouldInstallSynchronously { return postponingInstallation; }
- (void)installUpdate
{
showErrors = YES;
[SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHostBundle:hostBundle delegate:self synchronously:postponingInstallation];
[super installUpdate];
}
- (void)applicationWillTerminate:(NSNotification *)note
+3
View File
@@ -19,7 +19,10 @@
NSURLDownload *download;
NSString *downloadPath;
SUUnarchiver *unarchiver;
NSString *relaunchPath;
}
- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb;
+18 -3
View File
@@ -158,9 +158,19 @@
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]]];
}
- (BOOL)shouldInstallSynchronously { return NO; }
- (void)installUpdate
{
[SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHostBundle:hostBundle delegate:self synchronously:NO];
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems
[[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
relaunchPath = [targetPath retain];
[SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHostBundle:hostBundle delegate:self synchronously:[self shouldInstallSynchronously]];
}
- (void)installerFinishedForHostBundle:(NSBundle *)hb
@@ -173,9 +183,12 @@
- (void)relaunchHostApp
{
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
NSString *relaunchPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:nil];
@try
{
{
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
[NSException raise:@"SURelauncherNotFound" format:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath];
[NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:[hostBundle bundlePath], [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
}
@catch (NSException *e)
@@ -190,6 +203,7 @@
- (void)installerForHostBundle:(NSBundle *)hb failedWithError:(NSError *)error
{
if (hb != hostBundle) { return; }
[[NSFileManager defaultManager] removeFileAtPath:relaunchPath handler:NULL]; // Clean up the copied relauncher.
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
}
@@ -212,6 +226,7 @@
{
[hostBundle release];
[downloadPath release];
[relaunchPath release];
[unarchiver release];
[download release];
[super dealloc];
+1 -1
View File
@@ -16,7 +16,7 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate";
@implementation SUInstaller
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously;
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously
{
// Search subdirectories for the application
NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[hostBundle bundlePath] lastPathComponent], *alternateBundleFileName = [[hostBundle name] stringByAppendingPathExtension:[[hostBundle bundlePath] pathExtension]];
+2 -1
View File
@@ -44,7 +44,8 @@
- (void) relaunch
{
[[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:executablePath]];
[[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:executablePath]];
[[NSFileManager defaultManager] removeFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] handler:nil];
exit(0);
}