From b5d0501bea7ddfaf08a2b45c24cef7e7179f644e Mon Sep 17 00:00:00 2001 From: andym Date: Fri, 4 Apr 2008 15:44:52 +0000 Subject: [PATCH] Fixed an issue that would prevent people running FileVault from using Sparkle due to the disk image checking. Made the relaunch tool a tool instead of an app. This cleaned up a lot of code and made things less error-prone. Fixed a bug that sometimes prevented the relaunch tool itself from quitting on Leopard. --- Configurations/ConfigRelaunch.xcconfig | 2 - NSBundle+SUAdditions.m | 6 +- NSFileManager+Authentication.m | 29 ++++++++-- SUUpdater.m | 23 +++----- Sparkle.xcodeproj/project.pbxproj | 76 +++++++++++--------------- relaunch.m | 5 +- 6 files changed, 68 insertions(+), 73 deletions(-) diff --git a/Configurations/ConfigRelaunch.xcconfig b/Configurations/ConfigRelaunch.xcconfig index 215b2753..6cefd3c9 100644 --- a/Configurations/ConfigRelaunch.xcconfig +++ b/Configurations/ConfigRelaunch.xcconfig @@ -1,5 +1,3 @@ // Relaunch Tool only -INFOPLIST_FILE = Relaunch Tool-Info.plist PRODUCT_NAME = relaunch -WRAPPER_EXTENSION = app diff --git a/NSBundle+SUAdditions.m b/NSBundle+SUAdditions.m index 0ab57162..f6015ba2 100644 --- a/NSBundle+SUAdditions.m +++ b/NSBundle+SUAdditions.m @@ -56,7 +56,11 @@ // This check causes crashes on 10.3; for now, we'll just skip it. if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4) return NO; - return [[[NSWorkspace sharedWorkspace] propertiesForPath:[self bundlePath]] objectForKey:NSWorkspace_RBimagefilepath] != nil; + + NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[self bundlePath]]; + BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil; + BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"]; + return isDiskImage && !isFileVault; } - (NSArray *)systemProfile diff --git a/NSFileManager+Authentication.m b/NSFileManager+Authentication.m index a6907b09..60e873f0 100644 --- a/NSFileManager+Authentication.m +++ b/NSFileManager+Authentication.m @@ -85,9 +85,14 @@ static OSStatus AuthorizationExecuteWithPrivilegesAndWait( return res; } +- (NSString *)_temporaryCopyNameForPath:(NSString *)filename +{ + return [[[filename stringByDeletingPathExtension] stringByAppendingString:@".old"] stringByAppendingPathExtension:[filename pathExtension]]; +} + - (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst { - NSString *tmp = [[[dst stringByDeletingPathExtension] stringByAppendingString:@".old"] stringByAppendingPathExtension:[dst pathExtension]]; + NSString *tmp = [self _temporaryCopyNameForPath:dst]; const char* srcPath = [src fileSystemRepresentation]; const char* tmpPath = [tmp fileSystemRepresentation]; const char* dstPath = [dst fileSystemRepresentation]; @@ -189,11 +194,19 @@ static OSStatus AuthorizationExecuteWithPrivilegesAndWait( - (BOOL)copyPath:(NSString *)src overPath:(NSString *)dst withAuthentication:(BOOL)useAuthentication { + NSLog(@"Copying %@ to %@...", dst, [self _temporaryCopyNameForPath:dst]); if ([[NSFileManager defaultManager] isWritableFileAtPath:dst] && [[NSFileManager defaultManager] isWritableFileAtPath:[dst stringByDeletingLastPathComponent]]) { NSInteger tag = 0; - BOOL result = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[dst stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[dst lastPathComponent]] tag:&tag]; + BOOL result; + NSString *tmpPath = [self _temporaryCopyNameForPath:dst]; + NSLog(@"Performing traditional copy from %@ to %@...", src, dst); + result = [[NSFileManager defaultManager] movePath:dst toPath:tmpPath handler:self]; + NSLog(@"Moving %@ to %@...", src, dst); result &= [[NSFileManager defaultManager] copyPath:src toPath:dst handler:nil]; + NSLog(@"Moving %@ to the trash...", tmpPath); + result &= [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:tmpPath destination:@"" files:[NSArray arrayWithObject:[tmpPath lastPathComponent]] tag:&tag]; + NSLog(@"Success!"); // If the currently-running application is trusted, the new // version should be trusted as well. Remove it from the @@ -204,9 +217,8 @@ static OSStatus AuthorizationExecuteWithPrivilegesAndWait( // new home in case it's moved across filesystems: if that // happens, the move is actually a copy, and it may result // in the application being quarantined. - if (result) { + if (result) [self releaseFromQuarantine:dst]; - } return result; } @@ -216,11 +228,16 @@ static OSStatus AuthorizationExecuteWithPrivilegesAndWait( return NO; } --(BOOL)fileManager:(NSFileManager *)manager shouldProceedAfterError:(NSDictionary *)errorInfo +- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error copyingItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath { - NSLog(@"Sparkle: An error occurred in copying the new version of the product from %@ to %@: %@", [errorInfo objectForKey:@"Path"], [errorInfo objectForKey:@"ToPath"], [errorInfo objectForKey:@"Error"]); + NSLog(@"Sparkle: An error occurred in copying %@ to %@: %@", srcPath, dstPath, [error localizedDescription]); return NO; } +- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error movingItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath +{ + NSLog(@"Sparkle: An error occurred in moving %@ to %@: %@", srcPath, dstPath, [error localizedDescription]); + return NO; +} @end diff --git a/SUUpdater.m b/SUUpdater.m index 7f14260f..6dedf7dd 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -538,20 +538,6 @@ static SUUpdater *sharedUpdater = nil; return; } - // Now that we've found the path we care about, let's install it. - - // But before we do that, we need to copy out relaunch.app so we can run it later. - NSString *relaunchPath = [[[NSBundle bundleForClass:[self class]] executablePath] stringByDeletingLastPathComponent]; - if (!relaunchPath) // Slight hack to resolve issues with running within bundles - { - NSString *frameworkPath = [[[NSBundle mainBundle] sharedFrameworksPath] stringByAppendingPathComponent:@"Sparkle.framework"]; - NSBundle *framework = [NSBundle bundleWithPath:frameworkPath]; - relaunchPath = [[framework executablePath] stringByDeletingLastPathComponent]; - } - relaunchPath = [relaunchPath stringByAppendingPathComponent:@"relaunch.app/Contents/MacOS/relaunch"]; - NSString *newRelaunchPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"]; - [[NSFileManager defaultManager] copyPath:relaunchPath toPath:newRelaunchPath handler:nil]; - // Alright, *now* we can actually install the new version. int processIdentifierToWatch = [[NSProcessInfo processInfo] processIdentifier]; if (isPackage) @@ -592,8 +578,13 @@ static SUUpdater *sharedUpdater = nil; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; - - [NSTask launchedTaskWithLaunchPath:newRelaunchPath arguments:[NSArray arrayWithObjects:[hostBundle bundlePath], [NSString stringWithFormat:@"%d", processIdentifierToWatch], nil]]; + + NSString *relaunchPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:nil]; + @try { + [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:[hostBundle bundlePath], [NSString stringWithFormat:@"%d", processIdentifierToWatch], nil]]; + } @catch (NSException *e) { + NSLog(@"relaunch error: %@", e); + } [NSApp terminate:self]; } diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 1eb1c022..5d2a2e01 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -71,12 +71,11 @@ 61C1F2780DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61C1F2790DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */; }; 61C46F340D9C54F300B06326 /* SUUpdatePermissionPrompt.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61C46F330D9C54F300B06326 /* SUUpdatePermissionPrompt.nib */; }; - D1E42C370CE754C700F50EB9 /* relaunch.m in Sources */ = {isa = PBXBuildFile; fileRef = 613242130CD06CEF00106AA4 /* relaunch.m */; }; - D1E42C3B0CE755A000F50EB9 /* relaunch.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = D1E42C2F0CE754AE00F50EB9 /* relaunch.app */; }; + DAAEFC9B0DA5722F0051E0D0 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; + DAAEFD4E0DA572330051E0D0 /* relaunch.m in Sources */ = {isa = PBXBuildFile; fileRef = 613242130CD06CEF00106AA4 /* relaunch.m */; }; + DAAEFD510DA572550051E0D0 /* relaunch in CopyFiles */ = {isa = PBXBuildFile; fileRef = DAAEFC960DA571DF0051E0D0 /* relaunch */; }; FAEFA2F70D94AA7500472538 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; FAEFA2F80D94AA7900472538 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; - FAEFA2FA0D94AA8300472538 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; - FAEFA2FC0D94AA8900472538 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; FAEFA3040D94AB3400472538 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; FAEFA3050D94AB3400472538 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; /* End PBXBuildFile section */ @@ -89,12 +88,12 @@ remoteGlobalIDString = 8DC2EF4F0486A6940098B216; remoteInfo = Sparkle; }; - D1E42C3E0CE755D700F50EB9 /* PBXContainerItemProxy */ = { + DAAEFD4F0DA572460051E0D0 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; proxyType = 1; - remoteGlobalIDString = D1E42C2E0CE754AE00F50EB9; - remoteInfo = "Relaunch Tool"; + remoteGlobalIDString = DAAEFC950DA571DF0051E0D0; + remoteInfo = relaunch; }; /* End PBXContainerItemProxy section */ @@ -113,9 +112,9 @@ isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; - dstSubfolderSpec = 6; + dstSubfolderSpec = 7; files = ( - D1E42C3B0CE755A000F50EB9 /* relaunch.app in CopyFiles */, + DAAEFD510DA572550051E0D0 /* relaunch in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -265,8 +264,7 @@ 61C46F350D9C54F300B06326 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - D1E42C2F0CE754AE00F50EB9 /* relaunch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = relaunch.app; sourceTree = BUILT_PRODUCTS_DIR; }; - D1E42C330CE754AE00F50EB9 /* Relaunch Tool-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Relaunch Tool-Info.plist"; sourceTree = ""; }; + DAAEFC960DA571DF0051E0D0 /* relaunch */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = relaunch; sourceTree = BUILT_PRODUCTS_DIR; }; FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkDebug.xcconfig; sourceTree = ""; }; FA1941CB0D94A70100DD942E /* ConfigTestAppDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigTestAppDebug.xcconfig; sourceTree = ""; }; FA1941CC0D94A70100DD942E /* ConfigCommonRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigCommonRelease.xcconfig; sourceTree = ""; }; @@ -305,12 +303,11 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - D1E42C2D0CE754AE00F50EB9 /* Frameworks */ = { + DAAEFC940DA571DF0051E0D0 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FAEFA2FA0D94AA8300472538 /* Foundation.framework in Frameworks */, - FAEFA2FC0D94AA8900472538 /* AppKit.framework in Frameworks */, + DAAEFC9B0DA5722F0051E0D0 /* AppKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -322,7 +319,7 @@ children = ( 8DC2EF5B0486A6940098B216 /* Sparkle.framework */, 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */, - D1E42C2F0CE754AE00F50EB9 /* relaunch.app */, + DAAEFC960DA571DF0051E0D0 /* relaunch */, ); name = Products; sourceTree = ""; @@ -356,7 +353,6 @@ 089C1665FE841158C02AAC07 /* Resources */ = { isa = PBXGroup; children = ( - D1E42C330CE754AE00F50EB9 /* Relaunch Tool-Info.plist */, 8DC2EF5A0486A6940098B216 /* Info.plist */, 610D5A740A1670A4004AAD9C /* SUStatus.nib */, ); @@ -566,7 +562,7 @@ buildRules = ( ); dependencies = ( - D1E42C3F0CE755D700F50EB9 /* PBXTargetDependency */, + DAAEFD500DA572460051E0D0 /* PBXTargetDependency */, ); name = Sparkle; productInstallPath = "$(HOME)/Library/Frameworks"; @@ -574,22 +570,21 @@ productReference = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; productType = "com.apple.product-type.framework"; }; - D1E42C2E0CE754AE00F50EB9 /* Relaunch Tool */ = { + DAAEFC950DA571DF0051E0D0 /* relaunch tool */ = { isa = PBXNativeTarget; - buildConfigurationList = D1E42C360CE754AF00F50EB9 /* Build configuration list for PBXNativeTarget "Relaunch Tool" */; + buildConfigurationList = DAAEFC9A0DA571FD0051E0D0 /* Build configuration list for PBXNativeTarget "relaunch tool" */; buildPhases = ( - D1E42C2B0CE754AE00F50EB9 /* Resources */, - D1E42C2C0CE754AE00F50EB9 /* Sources */, - D1E42C2D0CE754AE00F50EB9 /* Frameworks */, + DAAEFC930DA571DF0051E0D0 /* Sources */, + DAAEFC940DA571DF0051E0D0 /* Frameworks */, ); buildRules = ( ); dependencies = ( ); - name = "Relaunch Tool"; - productName = "Relaunch Tool"; - productReference = D1E42C2F0CE754AE00F50EB9 /* relaunch.app */; - productType = "com.apple.product-type.application"; + name = "relaunch tool"; + productName = relaunch; + productReference = DAAEFC960DA571DF0051E0D0 /* relaunch */; + productType = "com.apple.product-type.tool"; }; /* End PBXNativeTarget section */ @@ -639,7 +634,7 @@ targets = ( 8DC2EF4F0486A6940098B216 /* Sparkle */, 61B5F90109C4CEE200B25A18 /* Sparkle Test App */, - D1E42C2E0CE754AE00F50EB9 /* Relaunch Tool */, + DAAEFC950DA571DF0051E0D0 /* relaunch tool */, ); }; /* End PBXProject section */ @@ -668,13 +663,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - D1E42C2B0CE754AE00F50EB9 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -732,11 +720,11 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - D1E42C2C0CE754AE00F50EB9 /* Sources */ = { + DAAEFC930DA571DF0051E0D0 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D1E42C370CE754C700F50EB9 /* relaunch.m in Sources */, + DAAEFD4E0DA572330051E0D0 /* relaunch.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -748,10 +736,10 @@ target = 8DC2EF4F0486A6940098B216 /* Sparkle */; targetProxy = 61B5F91B09C4CF7200B25A18 /* PBXContainerItemProxy */; }; - D1E42C3F0CE755D700F50EB9 /* PBXTargetDependency */ = { + DAAEFD500DA572460051E0D0 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = D1E42C2E0CE754AE00F50EB9 /* Relaunch Tool */; - targetProxy = D1E42C3E0CE755D700F50EB9 /* PBXContainerItemProxy */; + target = DAAEFC950DA571DF0051E0D0 /* relaunch tool */; + targetProxy = DAAEFD4F0DA572460051E0D0 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -922,14 +910,14 @@ }; name = Release; }; - D1E42C340CE754AF00F50EB9 /* Debug */ = { + DAAEFC980DA571DF0051E0D0 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */; buildSettings = { }; name = Debug; }; - D1E42C350CE754AF00F50EB9 /* Release */ = { + DAAEFC990DA571DF0051E0D0 /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */; buildSettings = { @@ -966,11 +954,11 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - D1E42C360CE754AF00F50EB9 /* Build configuration list for PBXNativeTarget "Relaunch Tool" */ = { + DAAEFC9A0DA571FD0051E0D0 /* Build configuration list for PBXNativeTarget "relaunch tool" */ = { isa = XCConfigurationList; buildConfigurations = ( - D1E42C340CE754AF00F50EB9 /* Debug */, - D1E42C350CE754AF00F50EB9 /* Release */, + DAAEFC980DA571DF0051E0D0 /* Debug */, + DAAEFC990DA571DF0051E0D0 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/relaunch.m b/relaunch.m index daf17688..b303b9bc 100644 --- a/relaunch.m +++ b/relaunch.m @@ -1,8 +1,5 @@ -// gcc -Wall -arch i386 -arch ppc -Os -s -framework AppKit -o relaunch relaunch.m -#import "Sparkle.h" #import -#import @interface TerminationListener : NSObject { @@ -48,7 +45,7 @@ - (void) relaunch { [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:executablePath]]; - [NSApp stop:self]; + exit(0); } @end