From 5f694f82af9b2e12987fe5051ecfe2cbea3e0ca1 Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Fri, 11 Dec 2009 12:53:52 +0100 Subject: [PATCH 01/16] Intermediate Update directory name contains the version number of the downloaded version --- SUBasicUpdateDriver.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 86b623fc..31b10339 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -141,7 +141,7 @@ // We create a temporary directory in /tmp and stick the file there. // Not using a GUID here because hdiutil (for DMGs) for some reason chokes on GUIDs. Too long? I really have no idea. - NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]]; + NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [updateItem versionString]]; NSString *desktopFolder = [@"~/Desktop" stringByExpandingTildeInPath]; NSString *tempDir = [desktopFolder stringByAppendingPathComponent:prefix]; int cnt=1; From d0425a140ae8ca95be7b517276b0879710aa501f Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Fri, 11 Dec 2009 13:28:10 +0100 Subject: [PATCH 02/16] Updating an application now longer shows the installation application n the Dock (LSUIElement) , Removed TransformProcessType call as it will force the installer application to show in the Dock. --- finish_installation-Info.plist | 4 ++++ finish_installation.m | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/finish_installation-Info.plist b/finish_installation-Info.plist index 875efd5b..cd1be6fa 100644 --- a/finish_installation-Info.plist +++ b/finish_installation-Info.plist @@ -26,5 +26,9 @@ MainMenu NSPrincipalClass NSApplication + LSBackgroundOnly + 1 + LSUIElement + 1 diff --git a/finish_installation.m b/finish_installation.m index d00fb1a3..11b63169 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -138,8 +138,8 @@ int main (int argc, const char * argv[]) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType( &psn, kProcessTransformToForegroundApplication ); + //ProcessSerialNumber psn = { 0, kCurrentProcess }; + //TransformProcessType( &psn, kProcessTransformToForegroundApplication ); [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; #if 0 // Cmdline tool From ad4e9c74e0863152e1a772e8c6b806e5842c26fc Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Fri, 11 Dec 2009 19:44:22 +0100 Subject: [PATCH 03/16] changed back 10.4 settings cause it broke the updater on 10.4 --- Sparkle.xcodeproj/project.pbxproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 3c21581a..1cafc1df 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -145,7 +145,7 @@ isa = PBXContainerItemProxy; containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; proxyType = 1; - remoteGlobalIDString = 55F9B5E310C68F890099848A; + remoteGlobalIDString = 55F9B5E310C68F890099848A /* finish_installation */; remoteInfo = finish_installation; }; /* End PBXContainerItemProxy section */ @@ -1145,6 +1145,7 @@ isa = XCBuildConfiguration; buildSettings = { GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = Debug; @@ -1153,6 +1154,7 @@ isa = XCBuildConfiguration; buildSettings = { GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = Release; @@ -1242,6 +1244,7 @@ isa = XCBuildConfiguration; buildSettings = { GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = "Release (GC dual-mode; 10.5-only)"; From db820fbb0f84538a29963f777e534d77b5b50247 Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Sat, 12 Dec 2009 13:52:42 +0100 Subject: [PATCH 04/16] updated the installer program to show an icon when the installation takes more than 1.2 seconds, long installations have a program in the Dock short installations just look like the program is restarting some variable renaming to no longer have camelCasePath for char * --- finish_installation.m | 91 ++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/finish_installation.m b/finish_installation.m index 11b63169..e159c377 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -7,54 +7,66 @@ #include +#define LONG_IMSTALLATION_TIME 1.2 // If the Installation takes longer than this time the Application Icon is shown in the Dock so that the user has some feedback. +#define CHECK_FOR_PARENT_TO_QUIT_TIME .5 // Time this app uses to recheck if the parent has already died. + @interface TerminationListener : NSObject { - const char *executablePath; - pid_t parentProcessId; - const char *folderPath; + const char *executablepath; + pid_t parentprocessid; + const char *folderpath; NSString *selfPath; NSTimer *watchdogTimer; + NSTimer *longInstallationTimer; SUHost *host; } -- (void) parentHasQuit; +- (void) parentHasQuit; -- (void) relaunch; -- (void) install; +- (void) relaunch; +- (void) install; -- (void) watchdog:(NSTimer *)timer; +- (void) showAppIconInDock:(NSTimer *)aTimer; +- (void) watchdog:(NSTimer *)aTimer; @end @implementation TerminationListener -- (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid folderPath: (const char*)inFolderPath +- (id) initWithExecutablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath: (const char*)infolderpath selfPath: (NSString*)inSelfPath { - self = [super init]; - if (self != nil) - { - executablePath = execPath; - parentProcessId = ppid; - folderPath = inFolderPath; - selfPath = [inSelfPath retain]; - BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already - - if( alreadyTerminated ) - [self parentHasQuit]; - else - watchdogTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(watchdog:) userInfo:nil repeats:YES] retain]; - } + if( !(self = [super init]) ) + return nil; + + executablepath = execpath; + parentprocessid = ppid; + folderpath = infolderpath; + selfPath = [inSelfPath retain]; + + BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already + + if( alreadyTerminated ) + [self parentHasQuit]; + else + watchdogTimer = [[NSTimer scheduledTimerWithTimeInterval:CHECK_FOR_PARENT_TO_QUIT_TIME target:self selector:@selector(watchdog:) userInfo:nil repeats:YES] retain]; + return self; } -(void) dealloc { + [longInstallationTimer invalidate]; + [longInstallationTimer release]; + longInstallationTimer = nil; + [selfPath release]; selfPath = nil; + [watchdogTimer release]; watchdogTimer = nil; + [host release]; host = nil; @@ -65,35 +77,42 @@ -(void) parentHasQuit { [watchdogTimer invalidate]; - - if( folderPath ) + longInstallationTimer = [[NSTimer scheduledTimerWithTimeInterval:LONG_IMSTALLATION_TIME target:self selector:@selector(showAppIconInDock:) userInfo:nil repeats:NO] retain]; + + if( folderpath ) [self install]; else [self relaunch]; } - -- (void)watchdog:(NSTimer *)timer +- (void) watchdog:(NSTimer *)aTimer { ProcessSerialNumber psn; - if (GetProcessForPID(parentProcessId, &psn) == procNotFound) + if (GetProcessForPID(parentprocessid, &psn) == procNotFound) [self parentHasQuit]; } +- (void)showAppIconInDock:(NSTimer *)aTimer; +{ + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType( &psn, kProcessTransformToForegroundApplication ); +} + + - (void) relaunch { NSString *appPath = nil; - if( !folderPath ) - appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablePath length:strlen(executablePath)]; + if( !folderpath ) + appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablepath length:strlen(executablepath)]; else appPath = [host installationPath]; [[NSWorkspace sharedWorkspace] openFile: appPath]; #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - if( folderPath ) + if( folderpath ) [[NSFileManager defaultManager] removeFileAtPath: [SUInstaller updateFolder] handler: nil]; [[NSFileManager defaultManager] removeFileAtPath: selfPath handler: nil]; #else - if( folderPath ) + if( folderpath ) [[NSFileManager defaultManager] removeItemAtPath: [SUInstaller updateFolder] error: NULL]; [[NSFileManager defaultManager] removeItemAtPath: selfPath error: NULL]; #endif @@ -101,9 +120,9 @@ } --(void) install +- (void) install { - NSBundle *theBundle = [NSBundle bundleWithPath: [NSString stringWithUTF8String: executablePath]]; + NSBundle *theBundle = [NSBundle bundleWithPath: [NSString stringWithUTF8String: executablepath]]; host = [[SUHost alloc] initWithBundle: theBundle]; SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: host]; // We quit anyway after we've installed, so leak this for now. @@ -112,18 +131,18 @@ maxProgressValue: 0 statusText: @""]; [statusCtl showWindow: self]; - [SUInstaller installFromUpdateFolder: [NSString stringWithUTF8String: folderPath] + [SUInstaller installFromUpdateFolder: [NSString stringWithUTF8String: folderpath] overHost: host delegate: self synchronously: NO versionComparator: [SUStandardVersionComparator defaultComparator]]; } -- (void)installerFinishedForHost:(SUHost *)aHost +- (void) installerFinishedForHost:(SUHost *)aHost { [self relaunch]; } -- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error +- (void) installerForHost:(SUHost *)host failedWithError:(NSError *)error { NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", error ); exit(EXIT_FAILURE); From 27f2b9c2199a2cd74b516933d899aa0eead04961 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:18:15 +0100 Subject: [PATCH 05/16] Move 10.4 SDK setting into xcconfig file. --- Configurations/ConfigCommon.xcconfig | 5 +++-- Sparkle.xcodeproj/project.pbxproj | 17 +---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index 2563b492..7e3307c6 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -3,7 +3,7 @@ PREBINDING = NO ZERO_LINK = NO CURRENT_PROJECT_VERSION = 1.5 -SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk +SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.4 MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5 MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.4 @@ -14,7 +14,8 @@ GCC_DEBUGGING_SYMBOLS = full GCC_PRECOMPILE_PREFIX_HEADER = YES GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h GCC_FAST_OBJC_DISPATCH = YES -ARCHS = ppc i386 x86_64 +GCC_VERSION = 4.0; +ARCHS = ppc i386 // Enable warnings GCC_WARN_CHECK_SWITCH_STATEMENTS = YES diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 1cafc1df..7fdad7f6 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -145,7 +145,7 @@ isa = PBXContainerItemProxy; containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; proxyType = 1; - remoteGlobalIDString = 55F9B5E310C68F890099848A /* finish_installation */; + remoteGlobalIDString = 55F9B5E310C68F890099848A; remoteInfo = finish_installation; }; /* End PBXContainerItemProxy section */ @@ -1163,10 +1163,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = ( - i386, - ppc, - ); COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_FIX_AND_CONTINUE = YES; @@ -1191,10 +1187,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = ( - i386, - ppc, - ); COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_ENABLE_FIX_AND_CONTINUE = NO; @@ -1219,10 +1211,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = ( - i386, - ppc, - ); GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -1268,7 +1256,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH)"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; @@ -1297,7 +1284,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; GCC_DYNAMIC_NO_PIC = NO; @@ -1326,7 +1312,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH)"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; From e49a69895ade1bf0fcbb89095475ada391cbf120 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:21:27 +0100 Subject: [PATCH 06/16] Fix authorized file moving code: - We now correctly handle the case where the containing directory doesn't allow us adding files without authorization (e.g. /Applications). - We do the quarantine release *before* the copy. --- SUPlainInstallerInternals.m | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index 22a73164..f38ae5b6 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -182,6 +182,24 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza snprintf(uidgid, sizeof(uidgid), "%d:%d", dstSB.st_uid, dstSB.st_gid); + // If the currently-running application is trusted, the new + // version should be trusted as well. Remove it from the + // quarantine to avoid a delay at launch, and to avoid + // presenting the user with a confusing trust dialog. + // + // This needs to be done after the application is moved to its + // new home with "mv" in case it's moved across filesystems: if + // that happens, "mv" actually performs a copy and may result + // in the application being quarantined. It also needs to be + // done before "chown" changes ownership, because the ownership + // change will almost certainly make it impossible to change + // attributes to release the files from the quarantine. + if (res) + { + SULog(@"releaseFromQuarantine"); + [self performSelectorOnMainThread:@selector(releaseFromQuarantine:) withObject:dst waitUntilDone:YES]; + } + if( res ) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination. { const char* coParams[] = { "-R", uidgid, srcPath, NULL }; @@ -213,22 +231,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams2 ); // } - // If the currently-running application is trusted, the new - // version should be trusted as well. Remove it from the - // quarantine to avoid a delay at launch, and to avoid - // presenting the user with a confusing trust dialog. - // - // This needs to be done after the application is moved to its - // new home with "mv" in case it's moved across filesystems: if - // that happens, "mv" actually performs a copy and may result - // in the application being quarantined. It also needs to be - // done before "chown" changes ownership, because the ownership - // change will almost certainly make it impossible to change - // attributes to release the files from the quarantine. - if (res) { - [self performSelectorOnMainThread:@selector(releaseFromQuarantine:) withObject:dst waitUntilDone:YES]; - } - AuthorizationFree(auth, 0); if (!res) @@ -342,17 +344,28 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error { - FSRef srcRef, dstRef, dstDirRev, movedRef, tmpDirRef; + FSRef srcRef, dstRef, dstDirRef, movedRef, tmpDirRef; OSErr err; BOOL hadFileAtDest = NO, didFindTrash = NO; NSString *tmpPath = [self _temporaryCopyNameForPath: dst didFindTrash: &didFindTrash]; + // Make FSRef for destination: err = FSPathMakeRefWithOptions((UInt8 *)[dst fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &dstRef, NULL); hadFileAtDest = (err == noErr); // There is a file at the destination, move it aside. If we normalized the name, we might not get here, so don't error. if( hadFileAtDest ) { if (0 != access([dst fileSystemRepresentation], W_OK) || 0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK)) + { return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error]; + } + } + else + { + if (0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK) + || 0 != access([[[dst stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK)) + { + return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error]; + } } if( hadFileAtDest ) @@ -362,9 +375,12 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &tmpDirRef, NULL); } - err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &dstDirRev, NULL); - if (err == noErr) + err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &dstDirRef, NULL); + + if (err == noErr && hadFileAtDest) + { err = FSMoveObjectSync(&dstRef, &tmpDirRef, (CFStringRef)[tmpPath lastPathComponent], &movedRef, 0); + } if (err != noErr && hadFileAtDest) { if (error != NULL) @@ -373,12 +389,12 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza } err = FSPathMakeRef((UInt8 *)[src fileSystemRepresentation], &srcRef, NULL); if (err == noErr) - err = FSCopyObjectSync(&srcRef, &dstDirRev, (CFStringRef)[dst lastPathComponent], NULL, 0); + err = FSCopyObjectSync(&srcRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], NULL, 0); if (err != noErr) { // We better move the old version back to its old location if( hadFileAtDest ) - FSMoveObjectSync(&movedRef, &dstDirRev, (CFStringRef)[dst lastPathComponent], &movedRef, 0); + FSMoveObjectSync(&movedRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], &movedRef, 0); if (error != NULL) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't copy %@ to %@.", src, dst] forKey:NSLocalizedDescriptionKey]]; return NO; From 4d7006950a1ddd72eff75143781c4443e323a66f Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:22:23 +0100 Subject: [PATCH 07/16] Make sure mdimport is run synchronously, not asynchronously. --- SUInstaller.m | 1 + 1 file changed, 1 insertion(+) diff --git a/SUInstaller.m b/SUInstaller.m index 64c50318..a2037bf4 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -129,6 +129,7 @@ static NSString* sUpdateFolder = nil; @try { [mdimport launch]; + [mdimport waitUntilExit]; } @catch (NSException * launchException) { From 5ec4c74b0bafb2a56825545e4e47a6c8ea0dac3b Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:24:48 +0100 Subject: [PATCH 08/16] Fix typo in LONG_INSTALLATION_TIME constant. --- finish_installation.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/finish_installation.m b/finish_installation.m index e159c377..77070e68 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -7,7 +7,7 @@ #include -#define LONG_IMSTALLATION_TIME 1.2 // If the Installation takes longer than this time the Application Icon is shown in the Dock so that the user has some feedback. +#define LONG_INSTALLATION_TIME 1.2 // If the Installation takes longer than this time the Application Icon is shown in the Dock so that the user has some feedback. #define CHECK_FOR_PARENT_TO_QUIT_TIME .5 // Time this app uses to recheck if the parent has already died. @interface TerminationListener : NSObject @@ -77,7 +77,9 @@ -(void) parentHasQuit { [watchdogTimer invalidate]; - longInstallationTimer = [[NSTimer scheduledTimerWithTimeInterval:LONG_IMSTALLATION_TIME target:self selector:@selector(showAppIconInDock:) userInfo:nil repeats:NO] retain]; + longInstallationTimer = [[NSTimer scheduledTimerWithTimeInterval: LONG_INSTALLATION_TIME + target: self selector: @selector(showAppIconInDock:) + userInfo:nil repeats:NO] retain]; if( folderpath ) [self install]; From 0e609cc5284a627aa53ea16343a8a987e190e3e6 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:28:14 +0100 Subject: [PATCH 09/16] Make sure we delete the temp directory. --- SUBasicUpdateDriver.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 31b10339..65d06b33 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -143,11 +143,13 @@ // Not using a GUID here because hdiutil (for DMGs) for some reason chokes on GUIDs. Too long? I really have no idea. NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [updateItem versionString]]; NSString *desktopFolder = [@"~/Desktop" stringByExpandingTildeInPath]; - NSString *tempDir = [desktopFolder stringByAppendingPathComponent:prefix]; + [tempDir release]; + tempDir = [[desktopFolder stringByAppendingPathComponent:prefix] retain]; int cnt=1; while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) { - tempDir = [desktopFolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]]; + [tempDir release]; + tempDir = [[desktopFolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]] retain]; } #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @@ -188,8 +190,8 @@ - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { // Get rid of what we've downloaded so far, if anything. - if (downloadPath != nil) - [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[downloadPath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[downloadPath lastPathComponent]] tag:NULL]; + if (tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here. + [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[tempDir lastPathComponent]] tag:NULL]; [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; } @@ -292,7 +294,7 @@ if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"]; - [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], [downloadPath stringByDeletingLastPathComponent], nil]]; + [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, nil]]; [NSApp terminate:self]; } @@ -303,9 +305,9 @@ - (void)cleanUp { #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil]; + [[NSFileManager defaultManager] removeFileAtPath: tempDir handler:nil]; #else - [[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath: tempDir error:NULL]; #endif } @@ -339,6 +341,7 @@ [updateItem release]; [download release]; [downloadPath release]; + [tempDir release]; [relaunchPath release]; [super dealloc]; } From 1b02ab5f7fc2d50b91e556c4c9c6f3fc0a839ed0 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:28:47 +0100 Subject: [PATCH 10/16] Make sure we delete the temp directory. --- SUBasicUpdateDriver.h | 1 + 1 file changed, 1 insertion(+) diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index ecf64279..21317496 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -18,6 +18,7 @@ NSURLDownload *download; NSString *downloadPath; + NSString *tempDir; NSString *relaunchPath; } From fa8aaced551e91fc3c591cf45e20f2fccccc4c9e Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:30:56 +0100 Subject: [PATCH 11/16] Make sure we also delete the temp dir when the user clicks "cancel" during the download. --- SUUIBasedUpdateDriver.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index b5552546..f85cb371 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -118,11 +118,16 @@ [statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self _humanReadableSizeFromDouble:[statusController progressValue]]]]; } -- (IBAction)cancelDownload:sender +- (IBAction)cancelDownload: (id)sender { if (download) [download cancel]; [self abortUpdate]; + if (tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here. + { + if( ![[NSFileManager defaultManager] removeFileAtPath: tempDir handler: nil] ) + [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[tempDir lastPathComponent]] tag:NULL]; + } } - (void)extractUpdate From 4c765d86ee58e9cdb748e8bb934c45520f34d47d Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:32:32 +0100 Subject: [PATCH 12/16] More correct way of turning a C-string path into an NSString. --- SUPlainInstallerInternals.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index f38ae5b6..1849ce25 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -119,7 +119,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza if( err == noErr ) err = FSRefMakePath( &trashRef, trashPath, MAXPATHLEN ); if( err == noErr ) - tempDir = [NSString stringWithUTF8String: (char*) trashPath]; + tempDir = [[NSFileManager defaultManager] stringWithFileSystemRepresentation: (char*) trashPath length: strlen((char*) trashPath)]; if( outDidFindTrash ) *outDidFindTrash = (tempDir != nil); if( !tempDir ) From cd93eb9098a2d687fc7114112fb15c778a562979 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:33:00 +0100 Subject: [PATCH 13/16] Method for removing a file with optional authorization. --- SUPlainInstallerInternals.h | 2 ++ SUPlainInstallerInternals.m | 66 ++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/SUPlainInstallerInternals.h b/SUPlainInstallerInternals.h index efbd5b68..24cd49a2 100644 --- a/SUPlainInstallerInternals.h +++ b/SUPlainInstallerInternals.h @@ -15,6 +15,8 @@ + (NSString *)temporaryNameForPath:(NSString *)path; + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error; + (void)_movePathToTrash:(NSString *)path; ++ (BOOL)_removeFileAtPath:(NSString *)path error: (NSError**)error; ++ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error; @end #endif diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index 1849ce25..37e79e97 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -262,7 +262,8 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza AuthorizationRef auth = NULL; OSStatus authStat = errAuthorizationDenied; - while (authStat == errAuthorizationDenied) { + while( authStat == errAuthorizationDenied ) + { authStat = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, @@ -321,6 +322,69 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return res; } + ++ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error +{ + // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! + + const char* srcPath = [src fileSystemRepresentation]; + + AuthorizationRef auth = NULL; + OSStatus authStat = errAuthorizationDenied; + while( authStat == errAuthorizationDenied ) + { + authStat = AuthorizationCreate(NULL, + kAuthorizationEmptyEnvironment, + kAuthorizationFlagDefaults, + &auth); + } + + BOOL res = NO; + if (authStat == errAuthorizationSuccess) + { + res = YES; + + if( res ) // If there's something at our tmp path (previous failed update or whatever) delete that first. + { + const char* rmParams[] = { "-rf", srcPath, NULL }; + res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams ); + if( !res ) + SULog(@"Can't remove destination file"); + } + + AuthorizationFree(auth, 0); + + if (!res) + { + // Something went wrong somewhere along the way, but we're not sure exactly where. + NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file remove from %@ failed.", src]; + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + } + } + else + { + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]]; + } + return res; +} + ++ (BOOL)_removeFileAtPath:(NSString *)path error: (NSError**)error +{ + BOOL success = YES; +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 + if( ![[NSFileManager defaultManager] removeFileAtPath: path handler: nil] ) +#else + if( ![[NSFileManager defaultManager] removeItemAtPath: path error: NULL] ) +#endif + { + success = [self _removeFileAtPathWithForcedAuthentication: path error: error]; + } + + return success; +} + + (void)_movePathToTrash:(NSString *)path { //SULog(@"Moving %@ to the trash.", path); From 2e8fa61a5ad7bcdb74569406c67c22ddf932b86d Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:34:25 +0100 Subject: [PATCH 14/16] More more correct way of creating an NSString from a C-string path. --- finish_installation.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/finish_installation.m b/finish_installation.m index 77070e68..35bf2530 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -124,7 +124,7 @@ - (void) install { - NSBundle *theBundle = [NSBundle bundleWithPath: [NSString stringWithUTF8String: executablepath]]; + NSBundle *theBundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: executablepath length:strlen(executablepath)]]; host = [[SUHost alloc] initWithBundle: theBundle]; SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: host]; // We quit anyway after we've installed, so leak this for now. @@ -133,7 +133,7 @@ maxProgressValue: 0 statusText: @""]; [statusCtl showWindow: self]; - [SUInstaller installFromUpdateFolder: [NSString stringWithUTF8String: folderpath] + [SUInstaller installFromUpdateFolder: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: folderpath length: strlen(folderpath)] overHost: host delegate: self synchronously: NO versionComparator: [SUStandardVersionComparator defaultComparator]]; @@ -166,11 +166,11 @@ int main (int argc, const char * argv[]) #if 0 // Cmdline tool NSString* selfPath = nil; if( argv[0][0] == '/' ) - selfPath = [NSString stringWithUTF8String: argv[0]]; + selfPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation: argv[0] length: strlen(argv[0])]; else { selfPath = [[NSFileManager defaultManager] currentDirectoryPath]; - selfPath = [selfPath stringByAppendingPathComponent: [NSString stringWithUTF8String: argv[0]]]; + selfPath = [selfPath stringByAppendingPathComponent: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: argv[0] length: strlen(argv[0])]]; } #else NSString* selfPath = [[NSBundle mainBundle] bundlePath]; From 9b116929adcae0e65d735500cd9afdda3095963f Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:34:49 +0100 Subject: [PATCH 15/16] Slightly more user-suitable error message. --- finish_installation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finish_installation.m b/finish_installation.m index 35bf2530..f52e5eee 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -146,7 +146,7 @@ - (void) installerForHost:(SUHost *)host failedWithError:(NSError *)error { - NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", error ); + NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", [error localizedDescription] ); exit(EXIT_FAILURE); } From 575bdda7682ffe3fedac39828e50d05724f1075a Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Mon, 14 Dec 2009 22:36:34 +0100 Subject: [PATCH 16/16] Make sure that, even on 10.4, we delete our temp folder. Also, we no longer use the stop-gap measure of trashing the temp folder, we really delete it after successful installation. --- finish_installation.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/finish_installation.m b/finish_installation.m index f52e5eee..08831e10 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -4,6 +4,7 @@ #import "SUHost.h" #import "SUStandardVersionComparator.h" #import "SUStatusController.h" +#import "SUPlainInstallerInternals.h" #include @@ -109,13 +110,15 @@ else appPath = [host installationPath]; [[NSWorkspace sharedWorkspace] openFile: appPath]; -#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 if( folderpath ) - [[NSFileManager defaultManager] removeFileAtPath: [SUInstaller updateFolder] handler: nil]; + { + NSError* theError = nil; + if( ![SUPlainInstaller _removeFileAtPath: [SUInstaller updateFolder] error: &theError] ) + SULog( @"Couldn't remove update folder: %@.", theError ); + } +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 [[NSFileManager defaultManager] removeFileAtPath: selfPath handler: nil]; #else - if( folderpath ) - [[NSFileManager defaultManager] removeItemAtPath: [SUInstaller updateFolder] error: NULL]; [[NSFileManager defaultManager] removeItemAtPath: selfPath error: NULL]; #endif exit(EXIT_SUCCESS);