diff options
Diffstat (limited to 'Foundation')
-rw-r--r-- | Foundation/GTMPath.m | 32 | ||||
-rw-r--r-- | Foundation/GTMPathTest.m | 19 |
2 files changed, 15 insertions, 36 deletions
diff --git a/Foundation/GTMPath.m b/Foundation/GTMPath.m index 76c84e9..da4b5a4 100644 --- a/Foundation/GTMPath.m +++ b/Foundation/GTMPath.m @@ -19,6 +19,10 @@ #import "GTMPath.h" #import "GTMDefines.h" +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +// NSFileManager has improved substantially in Leopard and beyond, so GTMPath +// is now deprecated. + @implementation GTMPath + (id)pathWithFullPath:(NSString *)fullPath { @@ -73,16 +77,8 @@ - (NSDictionary *)attributes { NSFileManager *mgr = [NSFileManager defaultManager]; - NSDictionary *attributes = nil; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - NSError *error = nil; - attributes = [mgr attributesOfItemAtPath:fullPath_ error:&error]; - if (error) { - _GTMDevLog(@"Error (%@) getting attributes for path %@", error, fullPath_); - } -#else - attributes = [mgr fileAttributesAtPath:fullPath_ traverseLink:NO]; -#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + NSDictionary *attributes = [mgr fileAttributesAtPath:fullPath_ + traverseLink:NO]; return attributes; } @@ -117,20 +113,8 @@ } if (!nascentPath) { - BOOL created = NO; NSFileManager *mgr = [NSFileManager defaultManager]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - NSError *error = nil; - created = [mgr createDirectoryAtPath:newPath - withIntermediateDirectories:NO - attributes:attributes - error:&error]; - if (error) { - _GTMDevLog(@"Error %@ creating directory at path %@", error, newPath); - } -#else - created = [mgr createDirectoryAtPath:newPath attributes:attributes]; -#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + BOOL created = [mgr createDirectoryAtPath:newPath attributes:attributes]; nascentPath = created ? [GTMPath pathWithFullPath:newPath] : nil; } @@ -174,3 +158,5 @@ } @end + +#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 diff --git a/Foundation/GTMPathTest.m b/Foundation/GTMPathTest.m index aec0731..1e58f50 100644 --- a/Foundation/GTMPathTest.m +++ b/Foundation/GTMPathTest.m @@ -20,6 +20,9 @@ #import "GTMPath.h" #import "GTMUnitTestDevLog.h" +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +// NSFileManager has improved substantially in Leopard and beyond, so GTMPath +// is now deprecated. @interface GTMPathTest : GTMTestCase { @private @@ -36,16 +39,8 @@ testDirectory_ = [[tmp stringByAppendingPathComponent:@"GTMPathTest"] retain]; STAssertNotNil(testDirectory_, nil); - BOOL created = NO; NSFileManager *mgr = [NSFileManager defaultManager]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - NSError *error = nil; - created = [mgr createDirectoryAtPath:testDirectory_ - withIntermediateDirectories:YES attributes:nil error:&error]; - STAssertNil(error, @"Can't create dir at %@ error:%@", testDirectory_, error); -#else - created = [mgr createDirectoryAtPath:testDirectory_ attributes:nil]; -#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + BOOL created = [mgr createDirectoryAtPath:testDirectory_ attributes:nil]; STAssertTrue(created, nil); } @@ -53,11 +48,7 @@ // Make sure it's safe to remove this directory before nuking it. STAssertNotNil(testDirectory_, nil); STAssertNotEqualObjects(testDirectory_, @"/", nil); -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - [[NSFileManager defaultManager] removeItemAtPath:testDirectory_ error:NULL]; -#else [[NSFileManager defaultManager] removeFileAtPath:testDirectory_ handler:nil]; -#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 [testDirectory_ release]; } @@ -241,3 +232,5 @@ } @end + +#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |