aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMPath.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-05-14 19:35:54 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-05-14 19:35:54 +0000
commit4f89cfe836e82f9445b98d733d6eb54b86e609d2 (patch)
treedd5f8eb01940af1a98922254baa93437936dc2ed /Foundation/GTMPath.m
parent4e865a397220fcca9975de0ed393ed7a145234d2 (diff)
[Author: dmaclach]
There are still a couple of errors occurring, but this fixes up the majority of stuff. I figured I'd send it out to you now to take a look at in the morning, and then we can clean up the last couple of issues. Not quite sure what to do about the naming of data files so that we can encompass ranges of system version (e.g. this file applies to 10.5 and 10.6 but not 10.4 or 10.7. R=thomasvl DELTA=10598 (10211 added, 70 deleted, 317 changed)
Diffstat (limited to 'Foundation/GTMPath.m')
-rw-r--r--Foundation/GTMPath.m40
1 files changed, 30 insertions, 10 deletions
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;
}