Skip to content

Commit

Permalink
Removed SL-deprecated NSFileManager methods. Left the old ones around…
Browse files Browse the repository at this point in the history
… #if'd for 10.4 support; I look forward to removing them. :)

Thanks for the patch, August.
  • Loading branch information
andymatuschak committed Jun 20, 2009
1 parent 54299d7 commit 7316a00
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
6 changes: 3 additions & 3 deletions SUAppcast.m
Expand Up @@ -59,8 +59,8 @@ - (void)downloadDidFinish:(NSURLDownload *)download
BOOL failed = NO; BOOL failed = NO;
NSArray *xmlItems = nil; NSArray *xmlItems = nil;
NSMutableArray *appcastItems = [NSMutableArray array]; NSMutableArray *appcastItems = [NSMutableArray array];
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:download handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil];
#else #else
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
#endif #endif
Expand Down Expand Up @@ -179,7 +179,7 @@ - (void)downloadDidFinish:(NSURLDownload *)download
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{ {
CFRelease(download); CFRelease(download);
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil];
#else #else
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
Expand Down
25 changes: 13 additions & 12 deletions SUBasicUpdateDriver.m
Expand Up @@ -138,14 +138,17 @@ - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSSt
name = [name stringByDeletingPathExtension]; name = [name stringByDeletingPathExtension];


// We create a temporary directory in /tmp and stick the file there. // We create a temporary directory in /tmp and stick the file there.
// Not using a GUID here because hdiutil for some reason chokes on GUIDs. Too long? I really have no idea. // 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], [host version]];
NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix]; NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
int cnt=1; int cnt=1;
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
{
tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]]; tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]];
#ifndef MAC_OS_X_VERSION_10_5 }
BOOL BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
#else #else
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
#endif #endif
Expand Down Expand Up @@ -226,15 +229,18 @@ - (void)installUpdate
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""]; NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
#ifndef MAC_OS_X_VERSION_10_5 NSError *error = nil;
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil]) if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
#else #else
[[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL];
if ([[NSFileManager defaultManager] copyItemAtPath:relaunchPathToCopy toPath:targetPath error:NULL]) if ([[NSFileManager defaultManager] copyItemAtPath:relaunchPathToCopy toPath:targetPath error:&error])
#endif #endif
relaunchPath = [targetPath retain]; relaunchPath = [targetPath retain];
else
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]];


[SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHost:host delegate:self synchronously:[self shouldInstallSynchronously] versionComparator:[self _versionComparator]]; [SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHost:host delegate:self synchronously:[self shouldInstallSynchronously] versionComparator:[self _versionComparator]];
} }
Expand Down Expand Up @@ -283,7 +289,7 @@ - (void)relaunchHostApp


- (void)cleanUp - (void)cleanUp
{ {
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil];
#else #else
[[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL];
Expand All @@ -293,11 +299,6 @@ - (void)cleanUp
- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error - (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
{ {
if (aHost != host) { return; } if (aHost != host) { return; }
#ifndef MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:relaunchPath handler:nil]; // Clean up the copied relauncher.
#else
[[NSFileManager defaultManager] removeItemAtPath:relaunchPath error:NULL]; // Clean up the copied relauncher.
#endif
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
} }


Expand Down
17 changes: 9 additions & 8 deletions SUDiskImageUnarchiver.m
Expand Up @@ -33,7 +33,7 @@ - (void)_extractDMG
if ([[NSFileManager defaultManager] fileExistsAtPath:mountPoint]) goto reportError; if ([[NSFileManager defaultManager] fileExistsAtPath:mountPoint]) goto reportError;


// create mount point folder // create mount point folder
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] createDirectoryAtPath:mountPoint attributes:nil]; [[NSFileManager defaultManager] createDirectoryAtPath:mountPoint attributes:nil];
#else #else
[[NSFileManager defaultManager] createDirectoryAtPath:mountPoint withIntermediateDirectories:YES attributes:nil error:NULL]; [[NSFileManager defaultManager] createDirectoryAtPath:mountPoint withIntermediateDirectories:YES attributes:nil error:NULL];
Expand All @@ -51,25 +51,26 @@ - (void)_extractDMG


// Now that we've mounted it, we need to copy out its contents. // Now that we've mounted it, we need to copy out its contents.
NSString *targetPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[mountPoint lastPathComponent]]; NSString *targetPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[mountPoint lastPathComponent]];
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath attributes:nil]) goto reportError; if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath attributes:nil]) goto reportError;
#else #else
if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:NULL]) goto reportError; if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:NULL]) goto reportError;
#endif #endif


// We can't just copyPath: from the volume root because that always fails. Seems to be a bug. // We can't just copyPath: from the volume root because that always fails. Seems to be a bug.
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
id subpathEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath:mountPoint] objectEnumerator], currentSubpath; id subpathEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath:mountPoint] objectEnumerator];
#else #else
id subpathEnumerator = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:mountPoint error:NULL] objectEnumerator], currentSubpath; id subpathEnumerator = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:mountPoint error:NULL] objectEnumerator];
#endif #endif
NSString *currentSubpath;
while ((currentSubpath = [subpathEnumerator nextObject])) while ((currentSubpath = [subpathEnumerator nextObject]))
{ {
NSString *currentFullPath = [mountPoint stringByAppendingPathComponent:currentSubpath]; NSString *currentFullPath = [mountPoint stringByAppendingPathComponent:currentSubpath];
// Don't bother trying (and failing) to copy out files we can't read. That's not going to be the app anyway. // Don't bother trying (and failing) to copy out files we can't read. That's not going to be the app anyway.
if (![[NSFileManager defaultManager] isReadableFileAtPath:currentFullPath]) continue; if (![[NSFileManager defaultManager] isReadableFileAtPath:currentFullPath]) continue;
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (![[NSFileManager defaultManager] copyPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath handler:nil]; if (![[NSFileManager defaultManager] copyPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath] handler:nil])
#else #else
if (![[NSFileManager defaultManager] copyItemAtPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath] error:NULL]) if (![[NSFileManager defaultManager] copyItemAtPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath] error:NULL])
#endif #endif
Expand All @@ -86,7 +87,7 @@ - (void)_extractDMG
if (mountedSuccessfully) if (mountedSuccessfully)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]]; [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]];
else else
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:mountPoint handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:mountPoint handler:nil];
#else #else
[[NSFileManager defaultManager] removeItemAtPath:mountPoint error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:mountPoint error:NULL];
Expand Down
2 changes: 1 addition & 1 deletion SUPipedUnarchiver.m
Expand Up @@ -48,7 +48,7 @@ - (void)_extractArchivePipingDataToCommand:(NSString *)command
FILE *fp = NULL, *cmdFP = NULL; FILE *fp = NULL, *cmdFP = NULL;


// Get the file size. // Get the file size.
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize]; NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize];
#else #else
NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:NULL] objectForKey:NSFileSize]; NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:NULL] objectForKey:NSFileSize];
Expand Down
2 changes: 1 addition & 1 deletion SUPlainInstaller.h
Expand Up @@ -11,9 +11,9 @@


#import "Sparkle.h" #import "Sparkle.h"
#import "SUInstaller.h" #import "SUInstaller.h"
#import "SUHost.h"
#import "SUVersionComparisonProtocol.h" #import "SUVersionComparisonProtocol.h"


@class SUHost;
@interface SUPlainInstaller : SUInstaller { } @interface SUPlainInstaller : SUInstaller { }
+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator; + (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator;
@end @end
Expand Down
1 change: 1 addition & 0 deletions SUPlainInstaller.m
Expand Up @@ -8,6 +8,7 @@


#import "SUPlainInstaller.h" #import "SUPlainInstaller.h"
#import "SUPlainInstallerInternals.h" #import "SUPlainInstallerInternals.h"
#import "SUHost.h"


NSString *SUInstallerPathKey = @"SUInstallerPath"; NSString *SUInstallerPathKey = @"SUInstallerPath";
NSString *SUInstallerHostKey = @"SUInstallerHost"; NSString *SUInstallerHostKey = @"SUInstallerHost";
Expand Down
6 changes: 3 additions & 3 deletions SUPlainInstallerInternals.m
Expand Up @@ -234,7 +234,7 @@ + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst erro
return [self _copyPathWithForcedAuthentication:src toPath:dst error:error]; return [self _copyPathWithForcedAuthentication:src toPath:dst error:error];


NSString *tmpPath = [self _temporaryCopyNameForPath:dst]; NSString *tmpPath = [self _temporaryCopyNameForPath:dst];
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (![[NSFileManager defaultManager] movePath:dst toPath:tmpPath handler:self]) if (![[NSFileManager defaultManager] movePath:dst toPath:tmpPath handler:self])
#else #else
if (![[NSFileManager defaultManager] moveItemAtPath:dst toPath:tmpPath error:NULL]) if (![[NSFileManager defaultManager] moveItemAtPath:dst toPath:tmpPath error:NULL])
Expand All @@ -244,7 +244,7 @@ + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst erro
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]];
return NO; return NO;
} }
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (![[NSFileManager defaultManager] copyPath:src toPath:dst handler:self]) if (![[NSFileManager defaultManager] copyPath:src toPath:dst handler:self])
#else #else
if (![[NSFileManager defaultManager] copyItemAtPath:src toPath:dst error:NULL]) if (![[NSFileManager defaultManager] copyItemAtPath:src toPath:dst error:NULL])
Expand Down Expand Up @@ -327,7 +327,7 @@ + (void)releaseFromQuarantine:(NSString*)root
// Only recurse if it's actually a directory. Don't recurse into a // Only recurse if it's actually a directory. Don't recurse into a
// root-level symbolic link. // root-level symbolic link.
NSDictionary* rootAttributes = NSDictionary* rootAttributes =
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] fileAttributesAtPath:root traverseLink:NO]; [[NSFileManager defaultManager] fileAttributesAtPath:root traverseLink:NO];
#else #else
[[NSFileManager defaultManager] attributesOfItemAtPath:root error:NULL]; [[NSFileManager defaultManager] attributesOfItemAtPath:root error:NULL];
Expand Down
2 changes: 1 addition & 1 deletion SUUIBasedUpdateDriver.m
Expand Up @@ -122,7 +122,7 @@ - (void)unarchiver:(SUUnarchiver *)ua extractedLength:(long)length
{ {
// We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress. // We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress.
if ([statusController maxProgressValue] == 0) if ([statusController maxProgressValue] == 0)
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[statusController setMaxProgressValue:[[[[NSFileManager defaultManager] fileAttributesAtPath:downloadPath traverseLink:NO] objectForKey:NSFileSize] doubleValue]]; [statusController setMaxProgressValue:[[[[NSFileManager defaultManager] fileAttributesAtPath:downloadPath traverseLink:NO] objectForKey:NSFileSize] doubleValue]];
#else #else
[statusController setMaxProgressValue:[[[[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:NULL] objectForKey:NSFileSize] doubleValue]]; [statusController setMaxProgressValue:[[[[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:NULL] objectForKey:NSFileSize] doubleValue]];
Expand Down
2 changes: 1 addition & 1 deletion relaunch.m
Expand Up @@ -39,7 +39,7 @@ - (void)watchdog:(NSTimer *)timer
- (void) relaunch - (void) relaunch
{ {
[[NSWorkspace sharedWorkspace] openFile:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablePath length:strlen(executablePath)]]; [[NSWorkspace sharedWorkspace] openFile:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablePath length:strlen(executablePath)]];
#ifndef MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] handler:nil]; [[NSFileManager defaultManager] removeFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] handler:nil];
#else #else
[[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] error:NULL]; [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] error:NULL];
Expand Down

0 comments on commit 7316a00

Please sign in to comment.