From 613b759077e5b66cc0fc80f1cafa043ddf4ada69 Mon Sep 17 00:00:00 2001 From: Brittany Tarvin Date: Mon, 17 Oct 2011 14:30:00 -0500 Subject: [PATCH] Fixed issues that led to crashes on Mac OS X 10.7 Lion. These fixes remove the use of the File Manager API that was causing crashes on Lion. This should resolve issue #827357. We are now using NSFileManager instead of the older File Manager API, but only on 10.6 and later. These changes should work for those targeting 10.4, but will allow users running 10.7 to still update without crashing. --- SUDiskImageUnarchiver.m | 27 ++++++++++------ SUPlainInstallerInternals.m | 64 +++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 7bc37b6a..80c83d29 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -65,15 +65,24 @@ mountedSuccessfully = YES; // Now that we've mounted it, we need to copy out its contents. - FSRef srcRef, dstRef; - OSStatus err; - err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL); - if (err != noErr) goto reportError; - err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL); - if (err != noErr) goto reportError; - - err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors); - if (err != noErr) goto reportError; + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { + // On 10.6 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357). + NSFileManager *manager = [[NSFileManager alloc] init]; + if (![manager copyItemAtPath:mountPoint toPath:[archivePath stringByDeletingLastPathComponent] error:NULL]) { + goto reportError; + } + } + else { + FSRef srcRef, dstRef; + OSStatus err; + err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL); + if (err != noErr) goto reportError; + err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL); + if (err != noErr) goto reportError; + + err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors); + if (err != noErr) goto reportError; + } [self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO]; goto finally; diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index bdde4581..630ad663 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -461,26 +461,58 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza 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) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; - return NO; + { + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) + { + NSFileManager *manager = [[NSFileManager alloc] init]; + BOOL success = [manager moveItemAtPath:dst toPath:tmpPath error:error]; + if (!success && hadFileAtDest) + { + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + } + + } else { + err = FSMoveObjectSync(&dstRef, &tmpDirRef, (CFStringRef)[tmpPath lastPathComponent], &movedRef, 0); + if (err != noErr && hadFileAtDest) + { + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + } + } } + err = FSPathMakeRef((UInt8 *)[src fileSystemRepresentation], &srcRef, NULL); if (err == noErr) - 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, &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; + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) + { + NSFileManager *manager = [[NSFileManager alloc] init]; + BOOL success = [manager copyItemAtPath:src toPath:dst error:error]; + if (!success) + { + // We better move the old version back to its old location + if( hadFileAtDest ) + success = [manager moveItemAtPath:tmpPath toPath:dst error:error]; + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + + } + } else { + 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, &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; + } + } } // If the currently-running application is trusted, the new