From cfe375b5f358ccb6ccbeffafbba2818c49add4fa Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Thu, 26 Sep 2013 15:58:57 -0400 Subject: [PATCH] Take care not to attempt copying the finish_installation.app unless we have actually succeeded in locating it. In the strange scenario that the finish_installation.app was not present in the Sparkle bundle, the target path was evaluated as being the host app's Application Support folder itself, and Sparkle would proceed to completely wipe out the host's Application Support folder as it tried to copy the non-existent --- SUBasicUpdateDriver.m | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index cb23e877..8c8836a6 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -315,22 +315,25 @@ [[updater delegate] updater:updater willInstallUpdate:updateItem]; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. - NSString *relaunchPathToCopy = [SPARKLE_BUNDLE pathForResource:@"finish_installation" ofType:@"app"]; - NSString *targetPath = [[host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. - NSError *error = nil; + NSString *relaunchPathToCopy = [SPARKLE_BUNDLE pathForResource:@"finish_installation" ofType:@"app"]; + if (relaunchPathToCopy != nil) + { + NSString *targetPath = [[host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; + // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. + NSError *error = nil; #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] attributes: [NSDictionary dictionary]]; + [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] attributes: [NSDictionary dictionary]]; #else - [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: [NSDictionary dictionary] error: &error]; + [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: [NSDictionary dictionary] error: &error]; #endif - // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. - if( [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error] ) - relaunchPath = [targetPath retain]; - else - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]]; - + if( [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error] ) + relaunchPath = [targetPath retain]; + else + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]]; + } + [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication:)]) [[updater delegate] updaterWillRelaunchApplication:updater];