aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMAbstractDOListener.h3
-rw-r--r--Foundation/GTMFileSystemKQueueTest.m45
-rw-r--r--Foundation/GTMNSFileManager+Path.m13
-rw-r--r--Foundation/GTMNSFileManager+PathTest.m51
-rw-r--r--Foundation/GTMNSString+FindFolder.m28
-rw-r--r--Foundation/GTMNSString+FindFolderTest.m6
-rw-r--r--Foundation/GTMPath.m40
-rw-r--r--Foundation/GTMPathTest.m21
8 files changed, 165 insertions, 42 deletions
diff --git a/Foundation/GTMAbstractDOListener.h b/Foundation/GTMAbstractDOListener.h
index 77eb111..38e8db4 100644
--- a/Foundation/GTMAbstractDOListener.h
+++ b/Foundation/GTMAbstractDOListener.h
@@ -16,6 +16,7 @@
// the License.
//
#import <Foundation/Foundation.h>
+#import "GTMDefines.h"
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
@class GTMReceivePortDelegate;
@@ -31,7 +32,7 @@
// GTM_ABSTRACTDOLISTENER_SUBCLASS_THREADMAIN_IMPL macro for easier debugging
// of stack traces. Please read it's description below.
//
-@interface GTMAbstractDOListener : NSObject {
+@interface GTMAbstractDOListener : NSObject <NSConnectionDelegate> {
@protected
NSString *registeredName_;
__weak Protocol *protocol_;
diff --git a/Foundation/GTMFileSystemKQueueTest.m b/Foundation/GTMFileSystemKQueueTest.m
index ec1edc0..a64fd2b 100644
--- a/Foundation/GTMFileSystemKQueueTest.m
+++ b/Foundation/GTMFileSystemKQueueTest.m
@@ -94,16 +94,28 @@
// make sure the files aren't in the way of the test
NSFileManager *fm = [NSFileManager defaultManager];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ [fm removeItemAtPath:testPath_ error:&error];
+ [fm removeItemAtPath:testPath2_ error:&error];
+#else
[fm removeFileAtPath:testPath_ handler:nil];
[fm removeFileAtPath:testPath2_ handler:nil];
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
}
- (void)tearDown {
// make sure we clean up the files from a failed test
NSFileManager *fm = [NSFileManager defaultManager];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ [fm removeItemAtPath:testPath_ error:&error];
+ [fm removeItemAtPath:testPath2_ error:&error];
+#else
[fm removeFileAtPath:testPath_ handler:nil];
[fm removeFileAtPath:testPath2_ handler:nil];
-
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
[testPath_ release];
testPath_ = nil;
[testPath2_ release];
@@ -208,7 +220,12 @@
// Close and delete
[testFH closeFile];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm removeItemAtPath:testPath_ error:&error], @"Err: %@", error);
+#else
STAssertTrue([fm removeFileAtPath:testPath_ handler:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
[self spinForEvents:helper];
STAssertEquals([helper totals], 2, nil);
@@ -268,7 +285,12 @@
// Close and delete
[testFH closeFile];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm removeItemAtPath:testPath_ error:&error], @"Err: %@", error);
+#else
STAssertTrue([fm removeFileAtPath:testPath_ handler:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Recreate
STAssertTrue([fm createFileAtPath:testPath_ contents:nil attributes:nil], nil);
@@ -291,8 +313,12 @@
// Close and delete
[testFH closeFile];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ STAssertTrue([fm removeItemAtPath:testPath_ error:&error], @"Err: %@", error);
+#else
STAssertTrue([fm removeFileAtPath:testPath_ handler:nil], nil);
-
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
// Spin the runloop for a second so that the helper callbacks fire
[self spinForEvents:helper];
STAssertEquals([helper totals], 4, nil);
@@ -357,7 +383,14 @@
STAssertEquals([helper2 totals], 1, nil);
// Move it and create the file again
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm moveItemAtPath:testPath_ toPath:testPath2_ error:&error],
+ @"Error: %@", error);
+#else
STAssertTrue([fm movePath:testPath_ toPath:testPath2_ handler:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
STAssertTrue([fm createFileAtPath:testPath_ contents:nil attributes:nil], nil);
NSFileHandle *testFHPrime
= [NSFileHandle fileHandleForWritingAtPath:testPath_];
@@ -387,7 +420,11 @@
// and now close old
[testFH closeFile];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ STAssertTrue([fm removeItemAtPath:testPath2_ error:&error], @"Err: %@", error);
+#else
STAssertTrue([fm removeFileAtPath:testPath2_ handler:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Spin the runloop for a second so that the helper callbacks fire
[self spinForEvents:helper];
@@ -396,7 +433,11 @@
// and now close new
[testFHPrime closeFile];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ STAssertTrue([fm removeItemAtPath:testPath_ error:&error], @"Err: %@", error);
+#else
STAssertTrue([fm removeFileAtPath:testPath_ handler:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Spin the runloop for a second so that the helper callbacks fire
[self spinForEvents:helper];
diff --git a/Foundation/GTMNSFileManager+Path.m b/Foundation/GTMNSFileManager+Path.m
index 195cd9e..bd0aef9 100644
--- a/Foundation/GTMNSFileManager+Path.m
+++ b/Foundation/GTMNSFileManager+Path.m
@@ -72,15 +72,24 @@
return nil;
// |basenames| will contain only the matching file names, not their full paths.
+ NSError *error = nil;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSArray *basenames = [self contentsOfDirectoryAtPath:directoryPath
+ error:&error];
+#else
NSArray *basenames = [self directoryContentsAtPath:directoryPath];
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Check if dir doesn't exist or couldn't be opened.
- if (basenames == nil)
+ if (basenames == nil) {
+ _GTMDevLog(@"Error: %@", error);
return nil;
+ }
// Check if dir is empty.
- if ([basenames count] == 0)
+ if ([basenames count] == 0) {
return basenames;
+ }
NSMutableArray *paths = [NSMutableArray arrayWithCapacity:[basenames count]];
NSString *basename;
diff --git a/Foundation/GTMNSFileManager+PathTest.m b/Foundation/GTMNSFileManager+PathTest.m
index 86f365f..5e4f845 100644
--- a/Foundation/GTMNSFileManager+PathTest.m
+++ b/Foundation/GTMNSFileManager+PathTest.m
@@ -28,20 +28,22 @@
- (void)setUp {
// make a directory to scribble in
- baseDir_ =
- [[NSTemporaryDirectory()
- stringByAppendingPathComponent:@"GTMNSFileManager_PathTest"] retain];
- if (baseDir_) {
- NSFileManager *fm = [NSFileManager defaultManager];
- if (![fm fileExistsAtPath:baseDir_] &&
- ![fm createDirectoryAtPath:baseDir_ attributes:nil]) {
- // COV_NF_START
- // if the dir exists or we failed to create it, drop the baseDir_
- [baseDir_ release];
- baseDir_ = nil;
- // COV_NF_END
- }
- }
+ NSString *base = NSTemporaryDirectory();
+ base = [base stringByAppendingPathComponent:@"GTMNSFileManager_PathTest"];
+ NSFileManager *fm = [NSFileManager defaultManager];
+ STAssertFalse([fm fileExistsAtPath:base], @"File exists at %@", base);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm createDirectoryAtPath:base
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error],
+ @"Unable to create %@: %@", base, error);
+#else
+ STAssertTrue([fm createDirectoryAtPath:baseDir_ attributes:nil],
+ @"Unable to create %@", base);
+#endif
+ baseDir_ = [base retain];
}
- (void)tearDown {
@@ -52,7 +54,7 @@
NSError *error = nil;
[fm removeItemAtPath:baseDir_ error:&error];
STAssertNil(error,
- @"Unable to delete %@: %@", baseDir_, [error description]);
+ @"Unable to delete %@: %@", baseDir_, error);
#else
[fm removeFileAtPath:baseDir_ handler:nil];
#endif
@@ -135,7 +137,16 @@
NSString *testDir = nil;
if ([testDirs[i] length]) {
testDir = [baseDir_ stringByAppendingPathComponent:testDirs[i]];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm createDirectoryAtPath:testDir
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error],
+ @"Can't create %@ (%@)", testDir, error);
+#else
STAssertTrue([fm createDirectoryAtPath:testDir attributes:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
} else {
testDir = baseDir_;
}
@@ -236,7 +247,17 @@
// create the empty dir
NSString *emptyDir = [baseDir_ stringByAppendingPathComponent:@"emptyDir"];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ STAssertTrue([fm createDirectoryAtPath:emptyDir
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error],
+ @"Can't create %@ (%@)", emptyDir, error);
+#else
STAssertTrue([fm createDirectoryAtPath:emptyDir attributes:nil], nil);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
// single
matches = [fm gtm_filePathsWithExtension:@"txt" inDirectory:emptyDir];
diff --git a/Foundation/GTMNSString+FindFolder.m b/Foundation/GTMNSString+FindFolder.m
index 3a44174..2e847e3 100644
--- a/Foundation/GTMNSString+FindFolder.m
+++ b/Foundation/GTMNSString+FindFolder.m
@@ -62,12 +62,30 @@
// it already exists
resultPath = subdirPath;
} else if (doCreate) {
-
+ parentFolderPath = [parentFolderPath stringByResolvingSymlinksInPath];
+ NSDictionary* attrs = nil;
+ BOOL createdSubDir = NO;
// create the subdirectory with the parent folder's attributes
- NSDictionary* attrs = [fileMgr fileAttributesAtPath:parentFolderPath
- traverseLink:YES];
- if ([fileMgr createDirectoryAtPath:subdirPath
- attributes:attrs]) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ attrs = [fileMgr attributesOfItemAtPath:parentFolderPath error:&error];
+ if (error) {
+ _GTMDevLog(@"Error %@ getting attributes of %@",
+ error, parentFolderPath);
+ }
+ createdSubDir = [fileMgr createDirectoryAtPath:subdirPath
+ withIntermediateDirectories:YES
+ attributes:attrs
+ error:&error];
+ if (error) {
+ _GTMDevLog(@"Error %@ creating directory at %@", error, subdirPath);
+ }
+#else
+ attrs = [fileMgr fileAttributesAtPath:parentFolderPath traverseLink:YES];
+ createdSubDir = [fileMgr createDirectoryAtPath:subdirPath
+ attributes:attrs];
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ if (createdSubDir) {
resultPath = subdirPath;
}
}
diff --git a/Foundation/GTMNSString+FindFolderTest.m b/Foundation/GTMNSString+FindFolderTest.m
index 66fd329..aae48cb 100644
--- a/Foundation/GTMNSString+FindFolderTest.m
+++ b/Foundation/GTMNSString+FindFolderTest.m
@@ -69,9 +69,15 @@
doCreate:NO];
STAssertEqualObjects(gtmCachePath2, gtmCachePath, nil);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ NSError *error = nil;
+ BOOL didRemove = [fileMgr removeItemAtPath:gtmCachePath error:&error];
+ STAssertTrue(didRemove, @"Error removing %@ (%@)", gtmCachePath, error);
+#else
BOOL didRemove = [fileMgr removeFileAtPath:gtmCachePath
handler:nil];
STAssertTrue(didRemove, @"Error removing %@", gtmCachePath);
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
}
@end
diff --git a/Foundation/GTMPath.m b/Foundation/GTMPath.m
index 28ffad0..76c84e9 100644
--- a/Foundation/GTMPath.m
+++ b/Foundation/GTMPath.m
@@ -17,7 +17,7 @@
//
#import "GTMPath.h"
-
+#import "GTMDefines.h"
@implementation GTMPath
@@ -31,7 +31,7 @@
- (id)initWithFullPath:(NSString *)fullPath {
if ((self = [super init])) {
- fullPath_ = [fullPath copy];
+ fullPath_ = [[fullPath stringByResolvingSymlinksInPath] copy];
if (![fullPath_ isAbsolutePath] || [self attributes] == nil) {
[self release];
return nil;
@@ -72,9 +72,18 @@
}
- (NSDictionary *)attributes {
- return [[NSFileManager defaultManager]
- fileAttributesAtPath:fullPath_
- traverseLink:YES];
+ 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
+ return attributes;
}
- (NSString *)fullPath {
@@ -103,14 +112,25 @@
// exists, we will end up returning a GTMPath for the pre-existing path.
NSString *newPath = [fullPath_ stringByAppendingPathComponent:name];
GTMPath *nascentPath = [GTMPath pathWithFullPath:newPath];
- if (nascentPath != nil && ![nascentPath isDirectory]) {
+ if (nascentPath && ![nascentPath isDirectory]) {
return nil; // Return nil because the path exists, but it's not a dir
}
- if (nascentPath == nil) {
- BOOL created = [[NSFileManager defaultManager]
- createDirectoryAtPath:newPath
- attributes:attributes];
+ 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
nascentPath = created ? [GTMPath pathWithFullPath:newPath] : nil;
}
diff --git a/Foundation/GTMPathTest.m b/Foundation/GTMPathTest.m
index 211206c..aec0731 100644
--- a/Foundation/GTMPathTest.m
+++ b/Foundation/GTMPathTest.m
@@ -36,9 +36,16 @@
testDirectory_ = [[tmp stringByAppendingPathComponent:@"GTMPathTest"] retain];
STAssertNotNil(testDirectory_, nil);
- BOOL created = [[NSFileManager defaultManager]
- createDirectoryAtPath:testDirectory_
- attributes: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
STAssertTrue(created, nil);
}
@@ -46,11 +53,11 @@
// 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] removeFileAtPath:testDirectory_ handler:nil];
-#else
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
[[NSFileManager defaultManager] removeItemAtPath:testDirectory_ error:NULL];
-#endif
+#else
+ [[NSFileManager defaultManager] removeFileAtPath:testDirectory_ handler:nil];
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
[testDirectory_ release];
}