From 38a70c61c460b551f1d63caee88c048e62345aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 24 Apr 2015 01:47:03 +0100 Subject: [PATCH 1/4] Use package.sparkle_guided.pkg instead of .sparkle_guided.plist indirection --- Sparkle/SUGuidedPackageInstaller.h | 33 +---- Sparkle/SUGuidedPackageInstaller.m | 224 ++++++----------------------- Sparkle/SUInstaller.m | 79 +++++----- 3 files changed, 85 insertions(+), 251 deletions(-) diff --git a/Sparkle/SUGuidedPackageInstaller.h b/Sparkle/SUGuidedPackageInstaller.h index 37df2657..429b6f5a 100644 --- a/Sparkle/SUGuidedPackageInstaller.h +++ b/Sparkle/SUGuidedPackageInstaller.h @@ -11,34 +11,10 @@ A guided installation allows Sparkle to download and install a package (pkg) or multi-package (mpkg) without user interaction. -A guided installation occurs when Sparkle finds a `.sparkle_guide.plist` in the root of the download; the file contains the relative path of the installer package to install. - -The file must be a property list and have a dictionary root. The only required key pair value is `package`. - -The `package` key value pair must be set to a relative path to the package or multi-package to install. The path is relative to the guide file. - -Example Contents of Sparkle Guide file: - - - - - - package - My Package.pkg - - - -Example Path of Sparkle Guide file: - - /Volumes/MyUpdateDiskImage/.sparkle_guide.plist - The installer package is installed using Mac OS X's built-in command line installer, `/usr/sbin/installer`. No installation interface is shown to the user. A guided installation can be started by applications other than the application being replaced. This is particularly useful where helper applications or agents are used. -## Notes -This method has been tested and successfully deployed on Mac OS X 10.4 - 10.8. - ## To Do - Replace the use of `AuthorizationExecuteWithPrivilegesAndWait`. This method remains because it is well supported and tested. Ideally a helper tool or XPC would be used. */ @@ -49,14 +25,11 @@ This method has been tested and successfully deployed on Mac OS X 10.4 - 10.8. #import "Sparkle.h" #import "SUInstaller.h" -extern NSString* SUInstallerGuidedInstallerFilename; // default filename for guided installer property list - -@interface SUGuidedPackageInstaller : SUInstaller { } -/*! Search for and return any installer guide */ -+ (NSString *)installerGuideWithinUpdateFolder:(NSString *)updateFolder; +@interface SUGuidedPackageInstaller : SUInstaller { +} /*! Perform the guided installation */ -+ (void)performInstallationToPath:(NSString *)path fromPath:(NSString *)installerGuide host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; ++ (void)performInstallationToPath:(NSString *)path fromPath:(NSString *)installerGuide host:(SUHost *)host delegate:delegate versionComparator:(id)comparator; @end #endif diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 4cab7d42..0437d33b 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -11,18 +11,6 @@ #import "SUGuidedPackageInstaller.h" -NSString* SUInstallerGuidedInstallerFilename = @".sparkle_guide.plist"; // top level file to search for within update folder - -// Constants -static NSString* SUGuidedPackageInstallerKeyGuidePath = @"SUGuidedPackageInstallerKeyGuidePath"; // NSString* -static NSString* SUGuidedPackageInstallerKeyGuide = @"SUGuidedPackageInstallerKeyGuide"; // NSDictionary* -static NSString* SUGuidedPackageInstallerKeyHost = @"SUGuidedPackageInstallerKeyHost"; // SUHost* -static NSString* SUGuidedPackageInstallerKeyDelegate = @"SUGuidedPackageInstallerKeyDelegate"; // id -static NSString* SUGuidedPackageInstallerKeyResult = @"SUGuidedPackageInstallerKeyResult"; // NSNumber[bool] -static NSString* SUGuidedPackageInstallerKeyError = @"SUGuidedPackageInstallerKeyError"; // NSError* - -static NSString* SUGuidedPackageInstallerGuideKeyPackage = @"package"; // NSString* - static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments) { sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL); @@ -46,83 +34,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return returnValue; } -@interface SUGuidedPackageInstaller (SUGuidedPackageInstallerAuthentication) -+ (AuthorizationRef)authorizationForExecutable:(NSString*)executablePath; -@end - -@interface SUGuidedPackageInstaller (SUGuidedPackageInstallerThreads) -// Perform the installation script -+ (void)performInstallationWithInfo:(NSDictionary *)theInfo; -// Complete the installation process -+ (void)finishInstallationWithInfo:(NSDictionary *)theInfo; -@end - -@implementation SUGuidedPackageInstaller - -// Search for and return any installer guide -+ (NSString *)installerGuideWithinUpdateFolder:(NSString *)updateFolder -{ - NSParameterAssert(updateFolder); - - NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:updateFolder]; - NSString *currentFile; - while ((currentFile = [dirEnum nextObject])) - { - if ([[currentFile lastPathComponent] isEqualToString:SUInstallerGuidedInstallerFilename]) - { - // Found an installer guide - return [updateFolder stringByAppendingPathComponent:currentFile]; - } - } - - // No guide found - return nil; -} - -+ (void)performInstallationToPath:(NSString *) __unused path fromPath:(NSString *)installerGuide host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id ) __unused comparator -{ - NSParameterAssert(installerGuide); - NSParameterAssert(host); - - // Fetch the contents of the guide - NSDictionary* guide = [NSDictionary dictionaryWithContentsOfFile:installerGuide]; - if (guide == nil) - { - NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Installer guide contents are malformed '%@'.",installerGuide]; - NSError* error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - [self finishInstallationToPath:installerGuide withResult:NO host:host error:error delegate:delegate]; - return; - } - - // Sanity check the contents of the guide - if ([guide objectForKey:SUGuidedPackageInstallerGuideKeyPackage] == NO) - { - NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Installer guide is missing '%@' entry.",SUGuidedPackageInstallerGuideKeyPackage]; - NSError* error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - [self finishInstallationToPath:installerGuide withResult:NO host:host error:error delegate:delegate]; - return; - } - - // Package up installation details to allow for synchronous installation - NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys: - installerGuide,SUGuidedPackageInstallerKeyGuidePath, - guide,SUGuidedPackageInstallerKeyGuide, - host,SUGuidedPackageInstallerKeyHost, - delegate,SUGuidedPackageInstallerKeyDelegate, - nil]; - - if (synchronously) - { - [self performInstallationWithInfo:info]; - } - else - { - [NSThread detachNewThreadSelector:@selector(performInstallationWithInfo:) toTarget:self withObject:info]; - } -} - -@end - @implementation SUGuidedPackageInstaller (SUGuidedPackageInstallerAuthentication) + (AuthorizationRef)authorizationForExecutable:(NSString*)executablePath @@ -177,99 +88,54 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @end -@implementation SUGuidedPackageInstaller (SUGuidedPackageInstallerThreads) +@implementation SUGuidedPackageInstaller -// Perform the installation script -+ (void)performInstallationWithInfo:(NSDictionary *)theInfo ++ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)host delegate:delegate versionComparator:(id)__unused comparator { - NSParameterAssert(theInfo); - - // Preflight - NSString* installerPath = @"/usr/sbin/installer"; // Mac OS X 10.2+ command line installer tool - NSError* error = nil; - - // Check installer executable exists - if ([[NSFileManager defaultManager] isExecutableFileAtPath:installerPath] == NO) - { - NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Guide installer tool is missing."]; - error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - } - - // Package is relative to installer guide file - NSString* absolutePackagePath = nil; - if (error == nil) - { - NSString* installerGuideParentFolderPath = [[theInfo objectForKey:SUGuidedPackageInstallerKeyGuidePath] stringByDeletingLastPathComponent]; - NSString* packagePath = [(NSDictionary*)[theInfo objectForKey:SUGuidedPackageInstallerKeyGuide] objectForKey:SUGuidedPackageInstallerGuideKeyPackage]; - NSAssert(packagePath,@"package entry is missing from guide"); - absolutePackagePath = [installerGuideParentFolderPath stringByAppendingPathComponent:packagePath]; - - // Sanity check absolute package path exists - if ([[NSFileManager defaultManager] fileExistsAtPath:absolutePackagePath] == NO) - { - NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Guide installer tool is missing."]; - error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - } - } - - // Create authorization for installer executable - AuthorizationRef auth = nil; - BOOL validInstallation = NO; - if (error == nil) - { - auth = [self authorizationForExecutable:installerPath]; - if (auth != NULL) - { - // Permission was granted to execute the installer with privileges - const char* const arguments[] = { -// [installerPath fileSystemRepresentation], - "-pkg", - [absolutePackagePath fileSystemRepresentation], - "-target", - "/", - NULL - }; - validInstallation = AuthorizationExecuteWithPrivilegesAndWait(auth, - [installerPath fileSystemRepresentation], - kAuthorizationFlagDefaults, - arguments); - // TODO: wait for communications pipe to close via fileno & CFSocketCreateWithNative - } - else - { - NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Script authorization denied."]; - error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; - } - } - - // Release any authorization - if (auth) - { - AuthorizationFree(auth,kAuthorizationFlagDefaults); - } - - // Modify info to include the installation script's outcome - NSMutableDictionary* resultInfo = [theInfo mutableCopy]; - [resultInfo setObject:[NSNumber numberWithBool:validInstallation] forKey:SUGuidedPackageInstallerKeyResult]; - if ((validInstallation == NO) && - (error)) - { - [resultInfo setObject:error forKey:SUGuidedPackageInstallerKeyError]; - } - - [self performSelectorOnMainThread:@selector(finishInstallationWithInfo:) withObject:resultInfo waitUntilDone:NO]; -} + NSParameterAssert(packagePath); + NSParameterAssert(host); -// Complete the installation process -+ (void)finishInstallationWithInfo:(NSDictionary *)theInfo -{ - NSParameterAssert(theInfo); - - [self finishInstallationToPath:[theInfo objectForKey:SUGuidedPackageInstallerKeyGuidePath] - withResult:[[theInfo objectForKey:SUGuidedPackageInstallerKeyResult] boolValue] - host:[theInfo objectForKey:SUGuidedPackageInstallerKeyHost] - error:[theInfo objectForKey:SUGuidedPackageInstallerKeyError] - delegate:[theInfo objectForKey:SUGuidedPackageInstallerKeyDelegate]]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + // Preflight + NSString* installerPath = @"/usr/sbin/installer"; // Mac OS X 10.2+ command line installer tool + NSError* error = nil; + + // Create authorization for installer executable + BOOL validInstallation = NO; + AuthorizationRef auth = [self authorizationForExecutable:installerPath]; + if (auth != NULL) + { + // Permission was granted to execute the installer with privileges + const char* const arguments[] = { + "-pkg", + [packagePath fileSystemRepresentation], + "-target", + "/", + NULL + }; + validInstallation = AuthorizationExecuteWithPrivilegesAndWait(auth, + [installerPath fileSystemRepresentation], + kAuthorizationFlagDefaults, + arguments); + // TODO: wait for communications pipe to close via fileno & CFSocketCreateWithNative + AuthorizationFree(auth,kAuthorizationFlagDefaults); + } + else + { + NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Script authorization denied."]; + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + [self finishInstallationToPath:destinationPath + withResult:validInstallation + host:host + error:error + delegate:delegate]; + + }); + }); } @end diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index c10434ae..9a40001f 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -14,7 +14,6 @@ #import "SUConstants.h" #import "SULog.h" - @implementation SUInstaller static NSString *sUpdateFolder = nil; @@ -43,7 +42,7 @@ static NSString *sUpdateFolder = nil; return NO; } -+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr ++ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr { // Search subdirectories for the application NSString *currentFile, @@ -51,14 +50,14 @@ static NSString *sUpdateFolder = nil; *bundleFileName = [[host bundlePath] lastPathComponent], *alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]]; BOOL isPackage = NO; + BOOL isGuided = NO; NSString *fallbackPackagePath = nil; NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder]; NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension]; - + sUpdateFolder = inUpdateFolder; - while ((currentFile = [dirEnum nextObject])) - { + while ((currentFile = [dirEnum nextObject])) { NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile]; NSString *currentFilename = [currentFile lastPathComponent]; NSString *currentExtension = [currentFile pathExtension]; @@ -69,28 +68,20 @@ static NSString *sUpdateFolder = nil; isPackage = NO; newAppDownloadPath = currentPath; break; - } - else if ([currentExtension isEqualToString:@"pkg"] || - [currentExtension isEqualToString:@"mpkg"]) - { - if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) - { + } else if ([currentExtension isEqualToString:@"pkg"] || + [currentExtension isEqualToString:@"mpkg"]) { + if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) { isPackage = YES; newAppDownloadPath = currentPath; break; - } - else - { + } else { // Remember any other non-matching packages we have seen should we need to use one of them as a fallback. fallbackPackagePath = currentPath; } - } - else - { + } else { // Try matching on bundle identifiers in case the user has changed the name of the host app NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath]; - if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]]) - { + if (incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]]) { isPackage = NO; newAppDownloadPath = currentPath; break; @@ -104,45 +95,49 @@ static NSString *sUpdateFolder = nil; // We don't have a valid path. Try to use the fallback package. - if (newAppDownloadPath == nil && fallbackPackagePath != nil) - { + if (newAppDownloadPath == nil && fallbackPackagePath != nil) { isPackage = YES; newAppDownloadPath = fallbackPackagePath; } - if (isPackagePtr) *isPackagePtr = isPackage; + if (isPackage) { + // foo.app -> foo.sparkle_guided.pkg or foo.sparkle_guided.mpkg + if ([[[newAppDownloadPath stringByDeletingPathExtension] pathExtension] isEqualToString:@"sparkle_guided"]) { + isGuided = YES; + } + } + + if (isPackagePtr) + *isPackagePtr = isPackage; + if (isGuidedPtr) + *isGuidedPtr = isGuided; return newAppDownloadPath; } + (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host { BOOL isPackage = NO; - NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage]; + NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage isGuided:nil]; return isPackage ? nil : path; } + (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id)delegate versionComparator:(id)comparator { - // Look for installer guide - NSString* installerGuide = [SUGuidedPackageInstaller installerGuideWithinUpdateFolder:inUpdateFolder]; - if (installerGuide) - { - [SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:installerGuide host:host delegate:delegate synchronously:NO versionComparator:comparator]; - } - else - { - BOOL isPackage = NO; - NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage]; + BOOL isPackage = NO; + BOOL isGuided = NO; + NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage isGuided:&isGuided]; - if (newAppDownloadPath == nil) - { - [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] delegate:delegate]; - } - else - { - [(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class])performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; - } - } + if (newAppDownloadPath == nil) { + [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] delegate:delegate]; + } else { + if (isPackage && isGuided) { + [SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + } else if (isPackage) { + [SUPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + } else { + [SUPlainInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + } + } } + (void)mdimportInstallationPath:(NSString *)installationPath From 77fd19a13412537e62d9102d8c9d0ba4d63aaa7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 24 Apr 2015 10:27:12 +0100 Subject: [PATCH 2/4] Use completion block instead of a delegate --- Sparkle/Autoupdate/Autoupdate.m | 34 ++++++++++++-------------- Sparkle/SUGuidedPackageInstaller.h | 2 +- Sparkle/SUGuidedPackageInstaller.m | 4 ++-- Sparkle/SUInstaller.h | 11 ++------- Sparkle/SUInstaller.m | 38 ++++++++++++------------------ Sparkle/SUPackageInstaller.m | 6 ++--- Sparkle/SUPlainInstaller.h | 2 +- Sparkle/SUPlainInstaller.m | 9 ++++--- 8 files changed, 43 insertions(+), 63 deletions(-) diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index 860d35bd..11887adf 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -18,7 +18,7 @@ static const NSTimeInterval SUInstallationTimeLimit = 5; */ static const NSTimeInterval SUParentQuitCheckInterval = .25; -@interface TerminationListener : NSObject +@interface TerminationListener : NSObject @property (copy) NSString *hostpath; @property (copy) NSString *executablepath; @@ -163,36 +163,32 @@ static const NSTimeInterval SUParentQuitCheckInterval = .25; [SUInstaller installFromUpdateFolder:self.folderpath overHost:self.host installationPath:self.installationPath - delegate:self - versionComparator:[SUStandardVersionComparator defaultComparator]]; -} - -- (void)installerFinishedForHost:(SUHost *)__unused aHost -{ - [self relaunch]; -} - -- (void)installerForHost:(SUHost *)__unused host failedWithError:(NSError *)error __attribute__((noreturn)) -{ - if (self.shouldShowUI) { - NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]); - } - exit(EXIT_FAILURE); + versionComparator:[SUStandardVersionComparator defaultComparator] + completionHandler:^(NSError *error) { + if (error) { + if (self.shouldShowUI) { + NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]); + } + exit(EXIT_FAILURE); + } else { + [self relaunch]; + } + }]; } @end int main(int __unused argc, const char __unused *argv[]) { - @autoreleasepool { + @autoreleasepool + { NSArray *args = [[NSProcessInfo processInfo] arguments]; if (args.count < 5 || args.count > 7) { return EXIT_FAILURE; } BOOL shouldShowUI = (args.count > 6) ? [args[6] boolValue] : YES; - if (shouldShowUI) - { + if (shouldShowUI) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } diff --git a/Sparkle/SUGuidedPackageInstaller.h b/Sparkle/SUGuidedPackageInstaller.h index 429b6f5a..92082a34 100644 --- a/Sparkle/SUGuidedPackageInstaller.h +++ b/Sparkle/SUGuidedPackageInstaller.h @@ -29,7 +29,7 @@ A guided installation can be started by applications other than the application } /*! Perform the guided installation */ -+ (void)performInstallationToPath:(NSString *)path fromPath:(NSString *)installerGuide host:(SUHost *)host delegate:delegate versionComparator:(id)comparator; ++ (void)performInstallationToPath:(NSString *)path fromPath:(NSString *)installerGuide host:(SUHost *)host versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler; @end #endif diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 0437d33b..6b5ae43d 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -90,7 +90,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @implementation SUGuidedPackageInstaller -+ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)host delegate:delegate versionComparator:(id)__unused comparator ++ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler { NSParameterAssert(packagePath); NSParameterAssert(host); @@ -132,7 +132,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza withResult:validInstallation host:host error:error - delegate:delegate]; + completionHandler:completionHandler]; }); }); diff --git a/Sparkle/SUInstaller.h b/Sparkle/SUInstaller.h index c1b01898..a1393d6d 100644 --- a/Sparkle/SUInstaller.h +++ b/Sparkle/SUInstaller.h @@ -12,21 +12,14 @@ #import #import "SUVersionComparisonProtocol.h" -@protocol SUInstallerDelegate; - @class SUHost; @interface SUInstaller : NSObject + (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host; -+ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id)delegate versionComparator:(id)comparator; -+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id)delegate; ++ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler; ++ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler; + (NSString *)updateFolder; @end -@protocol SUInstallerDelegate -- (void)installerFinishedForHost:(SUHost *)host; -- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error; -@end - #endif diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 9a40001f..3035a51e 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -121,21 +121,21 @@ static NSString *sUpdateFolder = nil; return isPackage ? nil : path; } -+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id)delegate versionComparator:(id)comparator ++ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler { BOOL isPackage = NO; BOOL isGuided = NO; NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage isGuided:&isGuided]; if (newAppDownloadPath == nil) { - [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] completionHandler:completionHandler]; } else { if (isPackage && isGuided) { - [SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + [SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler]; } else if (isPackage) { - [SUPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + [SUPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler]; } else { - [SUPlainInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator]; + [SUPlainInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler]; } } } @@ -149,8 +149,7 @@ static NSString *sUpdateFolder = nil; NSTask *mdimport = [[NSTask alloc] init]; [mdimport setLaunchPath:@"/usr/bin/mdimport"]; [mdimport setArguments:@[installationPath]]; - @try - { + @try { [mdimport launch]; [mdimport waitUntilExit]; } @@ -161,24 +160,17 @@ static NSString *sUpdateFolder = nil; } } -+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id)delegate ++ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler { - if (result) - { + if (result) { [self mdimportInstallationPath:installationPath]; - if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) { - dispatch_async(dispatch_get_main_queue(), ^{ - [delegate installerFinishedForHost:host]; - }); - } - } - else - { - if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)]) { - dispatch_async(dispatch_get_main_queue(), ^{ - [delegate installerForHost:host failedWithError:error]; - }); - } + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(nil); + }); + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(error); + }); } } diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index 23ad954f..8c4bef05 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -12,7 +12,7 @@ @implementation SUPackageInstaller -+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id)delegate versionComparator:(id)__unused comparator ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler { // Run installer using the "open" command to ensure it is launched in front of current application. // -W = wait until the app has quit. @@ -23,7 +23,7 @@ if (![[NSFileManager defaultManager] fileExistsAtPath:command]) { NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!" }]; - [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:error completionHandler:completionHandler]; return; } @@ -33,7 +33,7 @@ // Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine. dispatch_async(dispatch_get_main_queue(), ^{ - [self finishInstallationToPath:installationPath withResult:YES host:host error:nil delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:YES host:host error:nil completionHandler:completionHandler]; }); }); } diff --git a/Sparkle/SUPlainInstaller.h b/Sparkle/SUPlainInstaller.h index bb7827a6..9fd78f6f 100644 --- a/Sparkle/SUPlainInstaller.h +++ b/Sparkle/SUPlainInstaller.h @@ -21,7 +21,7 @@ @interface SUPlainInstaller : SUInstaller -+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id)delegate versionComparator:(id)comparator; ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler; @end diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index f9ff7faa..9d197b70 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -14,15 +14,14 @@ @implementation SUPlainInstaller -+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id)delegate versionComparator:(id)comparator ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler { // Prevent malicious downgrades if (![[[NSBundle bundleWithIdentifier:SUBundleIdentifier] infoDictionary][SUEnableAutomatedDowngradesKey] boolValue]) { - if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) - { + if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) { NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]]; NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; - [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:error completionHandler:completionHandler]; return; } } @@ -52,7 +51,7 @@ } dispatch_async(dispatch_get_main_queue(), ^{ - [self finishInstallationToPath:installationPath withResult:result host:host error:error delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:result host:host error:error completionHandler:completionHandler]; }); }); } From bb7af6145fbc634fd13e525975e2fb6d33de29d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 24 Apr 2015 10:31:42 +0100 Subject: [PATCH 3/4] Removed unused arg --- Sparkle/SUGuidedPackageInstaller.m | 4 +--- Sparkle/SUInstaller.h | 2 +- Sparkle/SUInstaller.m | 7 +++++-- Sparkle/SUPackageInstaller.m | 6 +++--- Sparkle/SUPlainInstaller.m | 6 ++++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 6b5ae43d..bc83d42b 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -90,10 +90,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @implementation SUGuidedPackageInstaller -+ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler ++ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)__unused host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler { NSParameterAssert(packagePath); - NSParameterAssert(host); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -130,7 +129,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza dispatch_async(dispatch_get_main_queue(), ^{ [self finishInstallationToPath:destinationPath withResult:validInstallation - host:host error:error completionHandler:completionHandler]; diff --git a/Sparkle/SUInstaller.h b/Sparkle/SUInstaller.h index a1393d6d..fe82f885 100644 --- a/Sparkle/SUInstaller.h +++ b/Sparkle/SUInstaller.h @@ -17,7 +17,7 @@ + (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host; + (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler; -+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler; ++ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler; + (NSString *)updateFolder; @end diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 3035a51e..19d1a718 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -128,7 +128,7 @@ static NSString *sUpdateFolder = nil; NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage isGuided:&isGuided]; if (newAppDownloadPath == nil) { - [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] completionHandler:completionHandler]; + [self finishInstallationToPath:installationPath withResult:NO error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] completionHandler:completionHandler]; } else { if (isPackage && isGuided) { [SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler]; @@ -160,7 +160,7 @@ static NSString *sUpdateFolder = nil; } } -+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler ++ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler { if (result) { [self mdimportInstallationPath:installationPath]; @@ -168,6 +168,9 @@ static NSString *sUpdateFolder = nil; completionHandler(nil); }); } else { + if (!error) { + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:nil]; + } dispatch_async(dispatch_get_main_queue(), ^{ completionHandler(error); }); diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index 8c4bef05..64637433 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -12,7 +12,7 @@ @implementation SUPackageInstaller -+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler ++ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)__unused host versionComparator:(id)__unused comparator completionHandler:(void (^)(NSError *))completionHandler { // Run installer using the "open" command to ensure it is launched in front of current application. // -W = wait until the app has quit. @@ -23,7 +23,7 @@ if (![[NSFileManager defaultManager] fileExistsAtPath:command]) { NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!" }]; - [self finishInstallationToPath:installationPath withResult:NO host:host error:error completionHandler:completionHandler]; + [self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler]; return; } @@ -33,7 +33,7 @@ // Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine. dispatch_async(dispatch_get_main_queue(), ^{ - [self finishInstallationToPath:installationPath withResult:YES host:host error:nil completionHandler:completionHandler]; + [self finishInstallationToPath:installationPath withResult:YES error:nil completionHandler:completionHandler]; }); }); } diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 9d197b70..1aeb6317 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -16,12 +16,14 @@ + (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id)comparator completionHandler:(void (^)(NSError *))completionHandler { + NSParameterAssert(host); + // Prevent malicious downgrades if (![[[NSBundle bundleWithIdentifier:SUBundleIdentifier] infoDictionary][SUEnableAutomatedDowngradesKey] boolValue]) { if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) { NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]]; NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; - [self finishInstallationToPath:installationPath withResult:NO host:host error:error completionHandler:completionHandler]; + [self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler]; return; } } @@ -51,7 +53,7 @@ } dispatch_async(dispatch_get_main_queue(), ^{ - [self finishInstallationToPath:installationPath withResult:result host:host error:error completionHandler:completionHandler]; + [self finishInstallationToPath:installationPath withResult:result error:error completionHandler:completionHandler]; }); }); } From 209d6db3a195c134f21c36da32fb8ab111b84fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 24 Apr 2015 11:10:41 +0100 Subject: [PATCH 4/4] Test guided installation --- Sparkle.xcodeproj/project.pbxproj | 10 +++- Sparkle/SUInstaller.m | 7 +++ Tests/Resources/test.sparkle_guided.pkg | Bin 0 -> 4956 bytes Tests/SUInstallerTest.m | 65 ++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Tests/Resources/test.sparkle_guided.pkg create mode 100644 Tests/SUInstallerTest.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index e0a5985a..b84c79ed 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -73,8 +73,10 @@ 55C14F9A136F045400649790 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 55C14FC7136F05E100649790 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 55E6F33219EC9F6C00005E76 /* SUErrors.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C1E81AE86E270014A3AB /* test archive.zip */; }; 5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */; }; + 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C1E81AE86E270014A3AB /* test archive.zip */; }; + 5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */; }; + 5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */; }; 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */; }; 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */; }; @@ -415,6 +417,8 @@ 5AEF45D9189D1CC90030D7DC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = ""; }; 5AF6C1E81AE86E270014A3AB /* test archive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "test archive.zip"; sourceTree = ""; }; 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPipedUnarchiverTest.m; sourceTree = ""; }; + 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallerTest.m; sourceTree = ""; }; + 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.sparkle_guided.pkg; sourceTree = ""; }; 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDSAVerifierTest.m; sourceTree = ""; }; 5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BinaryDelta; sourceTree = BUILT_PRODUCTS_DIR; }; 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */ = {isa = PBXFileReference; comments = "-Wno-shorten-64-to-32"; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bsdiff.c; sourceTree = ""; }; @@ -787,6 +791,7 @@ F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */, 5AF6C1E81AE86E270014A3AB /* test archive.zip */, 14958C6C19AEBC610061B14F /* test-pubkey.pem */, + 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */, ); path = Resources; sourceTree = ""; @@ -839,6 +844,7 @@ 142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */, F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */, 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */, + 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */, 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */, 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */, 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */, @@ -1276,6 +1282,7 @@ F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */, 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */, 14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */, + 5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1443,6 +1450,7 @@ 142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */, F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */, 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */, + 5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */, 14652F8219A9746000959E44 /* SULog.m in Sources */, 5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */, ); diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 19d1a718..2513973a 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -44,6 +44,9 @@ static NSString *sUpdateFolder = nil; + (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr { + NSParameterAssert(inUpdateFolder); + NSParameterAssert(host); + // Search subdirectories for the application NSString *currentFile, *newAppDownloadPath = nil, @@ -111,6 +114,10 @@ static NSString *sUpdateFolder = nil; *isPackagePtr = isPackage; if (isGuidedPtr) *isGuidedPtr = isGuided; + + if (!newAppDownloadPath) { + SULog(@"Searched %@ for %@.(app|pkg)", inUpdateFolder, bundleFileNameNoExtension); + } return newAppDownloadPath; } diff --git a/Tests/Resources/test.sparkle_guided.pkg b/Tests/Resources/test.sparkle_guided.pkg new file mode 100644 index 0000000000000000000000000000000000000000..f4933a800335c8f921ec271b53f14fe791e8c412 GIT binary patch literal 4956 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 FKLMVTQnvsA literal 0 HcmV?d00001 diff --git a/Tests/SUInstallerTest.m b/Tests/SUInstallerTest.m new file mode 100644 index 00000000..ceee0b6c --- /dev/null +++ b/Tests/SUInstallerTest.m @@ -0,0 +1,65 @@ +// +// SUInstallerTest.m +// Sparkle +// +// Created by Kornel on 24/04/2015. +// Copyright (c) 2015 Sparkle Project. All rights reserved. +// + +#import +#import +#import "SUHost.h" +#import "SUInstaller.h" +#import + +@interface SUInstallerTest : XCTestCase + +@end + +@implementation SUInstallerTest + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testInstallIfRoot +{ + uid_t uid = getuid(); + + if (uid) { + NSLog(@"Test must be run as root: sudo xctest -XCTest SUInstallerTest 'Sparkle Unit Tests.xctest'"); + return; + } + + NSString *expectedDestination = @"/tmp/sparklepkgtest.app"; + NSFileManager *fm = [NSFileManager defaultManager]; + [fm removeItemAtPath:expectedDestination error:nil]; + XCTAssertFalse([fm fileExistsAtPath:expectedDestination isDirectory:nil]); + + XCTestExpectation *done = [self expectationWithDescription:@"install finished"]; + + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *path = [bundle pathForResource:@"test.sparkle_guided" ofType:@"pkg"]; + XCTAssertNotNil(path); + + SUHost *host = [[SUHost alloc] initWithBundle:bundle]; + + [SUInstaller installFromUpdateFolder:[path stringByDeletingLastPathComponent] overHost:host installationPath:@"/tmp" versionComparator:nil completionHandler:^(NSError *error) { + XCTAssertNil(error); + XCTAssertTrue([fm fileExistsAtPath:expectedDestination isDirectory:nil]); + [done fulfill]; + }]; + + [self waitForExpectationsWithTimeout:40 handler:nil]; + [fm removeItemAtPath:expectedDestination error:nil]; +} + +@end