diff --git a/SUInstaller.h b/SUInstaller.h index 6d418995..7ad881b9 100644 --- a/SUInstaller.h +++ b/SUInstaller.h @@ -14,8 +14,8 @@ @class SUHost; @interface SUInstaller : NSObject { } -+ (void) installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; -+ (void) finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate; ++ (void) installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; ++ (void) finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate; + (NSString*) updateFolder; + (void) notifyDelegateOfFailure: (NSDictionary*)dict; @end diff --git a/SUInstaller.m b/SUInstaller.m index 8057fd89..92a013c1 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -43,7 +43,7 @@ static NSString* sUpdateFolder = nil; } -+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator ++ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator { // Search subdirectories for the application NSString *currentFile, @@ -109,15 +109,15 @@ static NSString* sUpdateFolder = nil; if (newAppDownloadPath == nil) { - [self finishInstallationWithResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate]; } else { - [(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously versionComparator:comparator]; + [(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously versionComparator:comparator]; } } -+ (void)mdimportHost:(SUHost *)host ++ (void)mdimportInstallationPath:(NSString *)installationPath { // *** GETS CALLED ON NON-MAIN THREAD! @@ -125,7 +125,7 @@ static NSString* sUpdateFolder = nil; NSTask *mdimport = [[[NSTask alloc] init] autorelease]; [mdimport setLaunchPath:@"/usr/bin/mdimport"]; - [mdimport setArguments:[NSArray arrayWithObject:[host installationPath]]]; + [mdimport setArguments:[NSArray arrayWithObject:installationPath]]; @try { [mdimport launch]; @@ -143,11 +143,11 @@ static NSString* sUpdateFolder = nil; #define SUNotifyDictErrorKey @"SUNotifyDictError" #define SUNotifyDictDelegateKey @"SUNotifyDictDelegate" -+ (void)finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate ++ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate { if (result) { - [self mdimportHost:host]; + [self mdimportInstallationPath:installationPath]; if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) [delegate performSelectorOnMainThread: @selector(installerFinishedForHost:) withObject: host waitUntilDone: NO]; } diff --git a/SUPackageInstaller.m b/SUPackageInstaller.m index 0eb24d92..f754231f 100644 --- a/SUPackageInstaller.m +++ b/SUPackageInstaller.m @@ -14,12 +14,13 @@ NSString *SUPackageInstallerCommandKey = @"SUPackageInstallerCommand"; NSString *SUPackageInstallerArgumentsKey = @"SUPackageInstallerArguments"; NSString *SUPackageInstallerHostKey = @"SUPackageInstallerHost"; NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate"; +NSString *SUPackageInstallerInstallationPathKey = @"SUPackageInstallerInstallationPathKey"; @implementation SUPackageInstaller + (void)finishInstallationWithInfo:(NSDictionary *)info { - [self finishInstallationWithResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]]; + [self finishInstallationToPath:[info objectForKey:SUPackageInstallerInstallationPathKey] withResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]]; } + (void)performInstallationWithInfo:(NSDictionary *)info @@ -35,7 +36,7 @@ NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate"; [pool drain]; } -+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator { NSString *command; NSArray *args; @@ -56,11 +57,11 @@ NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate"; if (![[NSFileManager defaultManager] fileExistsAtPath:command]) { NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]]; - [self finishInstallationWithResult:NO host:host error:error delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; } else { - NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, nil]; + NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, installationPath, SUPackageInstallerInstallationPathKey, nil]; if (synchronously) [self performInstallationWithInfo:info]; else diff --git a/SUPlainInstaller.h b/SUPlainInstaller.h index 2172e82c..e75f0401 100644 --- a/SUPlainInstaller.h +++ b/SUPlainInstaller.h @@ -20,7 +20,7 @@ @class SUHost; @interface SUPlainInstaller : SUInstaller { } -+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; @end #endif diff --git a/SUPlainInstaller.m b/SUPlainInstaller.m index 33d42683..62675c8c 100644 --- a/SUPlainInstaller.m +++ b/SUPlainInstaller.m @@ -18,6 +18,7 @@ static NSString * const SUInstallerHostKey = @"SUInstallerHost"; static NSString * const SUInstallerDelegateKey = @"SUInstallerDelegate"; static NSString * const SUInstallerResultKey = @"SUInstallerResult"; static NSString * const SUInstallerErrorKey = @"SUInstallerError"; +static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallationPath"; @implementation SUPlainInstaller @@ -25,7 +26,7 @@ static NSString * const SUInstallerErrorKey = @"SUInstallerError"; { // *** GETS CALLED ON NON-MAIN THREAD! - [self finishInstallationWithResult:[[info objectForKey:SUInstallerResultKey] boolValue] host:[info objectForKey:SUInstallerHostKey] error:[info objectForKey:SUInstallerErrorKey] delegate:[info objectForKey:SUInstallerDelegateKey]]; + [self finishInstallationToPath:[info objectForKey:SUInstallerInstallationPathKey] withResult:[[info objectForKey:SUInstallerResultKey] boolValue] host:[info objectForKey:SUInstallerHostKey] error:[info objectForKey:SUInstallerErrorKey] delegate:[info objectForKey:SUInstallerDelegateKey]]; } + (void)performInstallationWithInfo:(NSDictionary *)info @@ -37,7 +38,7 @@ static NSString * const SUInstallerErrorKey = @"SUInstallerError"; NSError *error = nil; NSString * oldPath = [[info objectForKey:SUInstallerHostKey] bundlePath]; - NSString * installationPath = [[info objectForKey:SUInstallerHostKey] installationPath]; + NSString * installationPath = [info objectForKey:SUInstallerInstallationPathKey]; BOOL result = [self copyPathWithAuthentication:[info objectForKey:SUInstallerPathKey] overPath: installationPath temporaryName:[info objectForKey:SUInstallerTempNameKey] error:&error]; if( result ) @@ -49,6 +50,7 @@ static NSString * const SUInstallerErrorKey = @"SUInstallerError"; } NSMutableDictionary *mutableInfo = [[info mutableCopy] autorelease]; [mutableInfo setObject:[NSNumber numberWithBool:result] forKey:SUInstallerResultKey]; + [mutableInfo setObject:installationPath forKey:SUInstallerInstallationPathKey]; if (!result && error) [mutableInfo setObject:error forKey:SUInstallerErrorKey]; [self performSelectorOnMainThread:@selector(finishInstallationWithInfo:) withObject:mutableInfo waitUntilDone:NO]; @@ -56,7 +58,7 @@ static NSString * const SUInstallerErrorKey = @"SUInstallerError"; [pool drain]; } -+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator { // Prevent malicious downgrades: #if !PERMIT_AUTOMATED_DOWNGRADES @@ -64,14 +66,14 @@ static NSString * const SUInstallerErrorKey = @"SUInstallerError"; { NSString * errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]]; NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - [self finishInstallationWithResult:NO host:host error:error delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; return; } #endif NSString *targetPath = [host installationPath]; NSString *tempName = [self temporaryNameForPath:targetPath]; - NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, targetPath, SUInstallerTargetPathKey, tempName, SUInstallerTempNameKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, nil]; + NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, targetPath, SUInstallerTargetPathKey, tempName, SUInstallerTempNameKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, installationPath, SUInstallerInstallationPathKey, nil]; if (synchronously) [self performInstallationWithInfo:info]; else diff --git a/finish_installation.m b/finish_installation.m index c0d2cc69..740de4b4 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -19,6 +19,7 @@ pid_t parentprocessid; const char *folderpath; NSString *selfPath; + NSString *installationPath; NSTimer *watchdogTimer; NSTimer *longInstallationTimer; SUHost *host; @@ -69,6 +70,8 @@ [selfPath release]; selfPath = nil; + + [installationPath release]; [watchdogTimer release]; watchdogTimer = nil; @@ -115,7 +118,7 @@ if( !folderpath || strcmp(executablepath, hostpath) != 0 ) appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablepath length:strlen(executablepath)]; else - appPath = [host installationPath]; + appPath = installationPath; [[NSWorkspace sharedWorkspace] openFile: appPath]; } @@ -139,6 +142,7 @@ { NSBundle *theBundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: hostpath length:strlen(hostpath)]]; host = [[SUHost alloc] initWithBundle: theBundle]; + installationPath = [[host installationPath] copy]; // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. if (shouldRelaunch) { @@ -151,6 +155,7 @@ [SUInstaller installFromUpdateFolder: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: folderpath length: strlen(folderpath)] overHost: host + installationPath: installationPath delegate: self synchronously: NO versionComparator: [SUStandardVersionComparator defaultComparator]]; }