Permalink
Browse files

Removed SL-deprecated NSFileManager methods. Left the old ones around…

… #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 7316a00e9c92f54c552076a44c38241c0f1bf975
Showing with 33 additions and 30 deletions.
  1. +3 −3 SUAppcast.m
  2. +13 −12 SUBasicUpdateDriver.m
  3. +9 −8 SUDiskImageUnarchiver.m
  4. +1 −1 SUPipedUnarchiver.m
  5. +1 −1 SUPlainInstaller.h
  6. +1 −0 SUPlainInstaller.m
  7. +3 −3 SUPlainInstallerInternals.m
  8. +1 −1 SUUIBasedUpdateDriver.m
  9. +1 −1 relaunch.m
View
@@ -59,8 +59,8 @@ - (void)downloadDidFinish:(NSURLDownload *)download
BOOL failed = NO;
NSArray *xmlItems = nil;
NSMutableArray *appcastItems = [NSMutableArray array];
-#ifndef MAC_OS_X_VERSION_10_5
- [[NSFileManager defaultManager] removeFileAtPath:download handler:nil];
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ [[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil];
#else
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
#endif
@@ -179,7 +179,7 @@ - (void)downloadDidFinish:(NSURLDownload *)download
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
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];
#else
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
View
@@ -138,14 +138,17 @@ - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSSt
name = [name stringByDeletingPathExtension];
// 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 *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
int cnt=1;
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
+ {
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
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
#endif
@@ -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.
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
- // 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
+ // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
+ NSError *error = nil;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
#else
[[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
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]];
}
@@ -283,7 +289,7 @@ - (void)relaunchHostApp
- (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];
#else
[[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL];
@@ -293,11 +299,6 @@ - (void)cleanUp
- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
{
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]]];
}
View
@@ -33,7 +33,7 @@ - (void)_extractDMG
if ([[NSFileManager defaultManager] fileExistsAtPath:mountPoint]) goto reportError;
// 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];
#else
[[NSFileManager defaultManager] createDirectoryAtPath:mountPoint withIntermediateDirectories:YES attributes:nil error:NULL];
@@ -51,25 +51,26 @@ - (void)_extractDMG
// Now that we've mounted it, we need to copy out its contents.
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;
#else
if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:NULL]) goto reportError;
#endif
// 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
- id subpathEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath:mountPoint] objectEnumerator], currentSubpath;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ id subpathEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath:mountPoint] objectEnumerator];
#else
- id subpathEnumerator = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:mountPoint error:NULL] objectEnumerator], currentSubpath;
+ id subpathEnumerator = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:mountPoint error:NULL] objectEnumerator];
#endif
+ NSString *currentSubpath;
while ((currentSubpath = [subpathEnumerator nextObject]))
{
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.
if (![[NSFileManager defaultManager] isReadableFileAtPath:currentFullPath]) continue;
-#ifndef MAC_OS_X_VERSION_10_5
- if (![[NSFileManager defaultManager] copyPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath handler:nil];
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ if (![[NSFileManager defaultManager] copyPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath] handler:nil])
#else
if (![[NSFileManager defaultManager] copyItemAtPath:currentFullPath toPath:[targetPath stringByAppendingPathComponent:currentSubpath] error:NULL])
#endif
@@ -86,7 +87,7 @@ - (void)_extractDMG
if (mountedSuccessfully)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]];
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];
#else
[[NSFileManager defaultManager] removeItemAtPath:mountPoint error:NULL];
View
@@ -48,7 +48,7 @@ - (void)_extractArchivePipingDataToCommand:(NSString *)command
FILE *fp = NULL, *cmdFP = NULL;
// 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];
#else
NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:NULL] objectForKey:NSFileSize];
View
@@ -11,9 +11,9 @@
#import "Sparkle.h"
#import "SUInstaller.h"
-#import "SUHost.h"
#import "SUVersionComparisonProtocol.h"
+@class SUHost;
@interface SUPlainInstaller : SUInstaller { }
+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator;
@end
View
@@ -8,6 +8,7 @@
#import "SUPlainInstaller.h"
#import "SUPlainInstallerInternals.h"
+#import "SUHost.h"
NSString *SUInstallerPathKey = @"SUInstallerPath";
NSString *SUInstallerHostKey = @"SUInstallerHost";
@@ -234,7 +234,7 @@ + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst erro
return [self _copyPathWithForcedAuthentication:src toPath:dst error:error];
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])
#else
if (![[NSFileManager defaultManager] moveItemAtPath:dst toPath:tmpPath error:NULL])
@@ -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]];
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])
#else
if (![[NSFileManager defaultManager] copyItemAtPath:src toPath:dst error:NULL])
@@ -327,7 +327,7 @@ + (void)releaseFromQuarantine:(NSString*)root
// Only recurse if it's actually a directory. Don't recurse into a
// root-level symbolic link.
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];
#else
[[NSFileManager defaultManager] attributesOfItemAtPath:root error:NULL];
View
@@ -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.
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]];
#else
[statusController setMaxProgressValue:[[[[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:NULL] objectForKey:NSFileSize] doubleValue]];
View
@@ -39,7 +39,7 @@ - (void)watchdog:(NSTimer *)timer
- (void) relaunch
{
[[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];
#else
[[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] error:NULL];

0 comments on commit 7316a00

Please sign in to comment.