aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar dmaclach <dmaclach@gmail.com>2018-11-13 13:39:56 -0800
committerGravatar GitHub <noreply@github.com>2018-11-13 13:39:56 -0800
commita116cfebae03926f059104ae69d77f8ba8908666 (patch)
treef7e1d0aaf6ca082c2264bcbc166cc605ab33d233 /Foundation
parent573a7d90f67f856546cccbfb7137360b4d7ba712 (diff)
Remove GTMPath (#200)
It has been obsolete since 10.5.
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMPath.h136
-rw-r--r--Foundation/GTMPath.m175
-rw-r--r--Foundation/GTMPathTest.m239
3 files changed, 0 insertions, 550 deletions
diff --git a/Foundation/GTMPath.h b/Foundation/GTMPath.h
deleted file mode 100644
index ec6009a..0000000
--- a/Foundation/GTMPath.h
+++ /dev/null
@@ -1,136 +0,0 @@
-//
-// GTMPath.h
-//
-// Copyright 2007-2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy
-// of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-//
-
-#import <Foundation/Foundation.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.
-
-// GTMPath
-//
-// This class represents a single, absolute file system path. The represented
-// path must exist at the time of creation. This class also allows you to easily
-// create new paths (or full hierarchies) based on existing GTMPath instances.
-//
-// Given a GTMPath instance, new files and directories can be created inside
-// that path providing the instance refers to a directory. It is an error to try
-// to create a file/directory from a GTMPath that represents a file (this should
-// be common sense: clearly mkdir /etc/passwd/foo won't work).
-//
-// === Examples ===
-//
-// 1. This sample creates a GTMPath that references /tmp, then gets the
-// attributes for that directory.
-//
-// GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
-// NSDictionary *attr = [tmp attributes];
-//
-//
-// 2. This sample creates a new directory inside /tmp named "foo".
-//
-// GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
-// GTMPath *foo = [tmp createDirectoryName:@"foo" mode:0755];
-//
-//
-// 3. This sample creates a GTMPath instance that represents a user's ~/Library
-// folder.
-//
-// GTMPath *library = [GTMPath pathWithFullPath:@"/Users/bob/Library"];
-// ...
-//
-//
-// 4. This sample creates a directory hierarchy, where each level has its own
-// mode. Notice that the return value from these -create* methods is the
-// GTMPath that was just created. This allows these creation calls to be
-// chained together enabling easy creation of directory hierarchies.
-// This is one of the big benefits of this class.
-//
-// GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
-// GTMPath *baz = [[[tmp createDirectoryName:@"foo" mode:0755]
-// createDirectoryName:@"bar" mode:0756]
-// createDirectoryName:@"baz" mode:0757];
-//
-@interface GTMPath : NSObject {
- @private
- NSString *fullPath_;
-}
-
-// Returns a GTMPath instance that represents the full path specified by
-// |fullPath|. Note that |fullPath| MUST be an absolute path.
-+ (id)pathWithFullPath:(NSString *)fullPath;
-
-// Returns a GTMPath instance that represents the full path specified by
-// |fullPath|. Note that |fullPath| MUST be an absolute path. This method is the
-// designated initializer.
-- (id)initWithFullPath:(NSString *)fullPath;
-
-// Returns the name of this GTMPath instance. This is not the full path. It is
-// just the component name of this GTMPath instance. This is equivalent to
-// the Unix basename(3) function.
-- (NSString *)name;
-
-// Returns this path's parent GTMPath. This method will ONLY (and always) return
-// nil when |name| is "/". In otherwords, parent will be nil IFF this GTMPath
-// instance represents the root path, because "/" doesn't really have a parent.
-- (GTMPath *)parent;
-
-// Returns YES if this GTMPath represents a directory.
-- (BOOL)isDirectory;
-
-// Returns YES if this GTMPath instance represents the root path "/".
-- (BOOL)isRoot;
-
-// Returns the file system attributes of the path represented by this GTMPath
-// instance. See -[NSFileManager fileAttributesAtPath:...] for details.
-- (NSDictionary *)attributes;
-
-// Returns a string representation of the absolute path represented by this
-// GTMPath instance.
-- (NSString *)fullPath;
-
-@end
-
-
-// Methods for creating files and directories inside a GTMPath instance. These
-// methods are only allowed to be called on GTMPath instances that represent
-// directories. See the NSFileManager documentation for details about the
-// |attributes| parameters.
-@interface GTMPath (GTMPathGeneration)
-
-// Creates a new directory with the specified mode or attributes inside the
-// current GTMPath instance. If the creation is successful, a GTMPath for the
-// newly created directory is returned. Otherwise, nil is returned.
-- (GTMPath *)createDirectoryName:(NSString *)name mode:(mode_t)mode;
-- (GTMPath *)createDirectoryName:(NSString *)name
- attributes:(NSDictionary *)attributes;
-
-// Creates a new file with the specified mode or attributes inside the
-// current GTMPath instance. If the creation is successful, a GTMPath for the
-// newly created file is returned. Otherwise, nil is returned. |data| is the
-// data to put in the file when created.
-- (GTMPath *)createFileName:(NSString *)name mode:(mode_t)mode;
-- (GTMPath *)createFileName:(NSString *)name
- attributes:(NSDictionary *)attributes;
-- (GTMPath *)createFileName:(NSString *)name
- attributes:(NSDictionary *)attributes
- data:(NSData *)data;
-
-@end
-
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
diff --git a/Foundation/GTMPath.m b/Foundation/GTMPath.m
deleted file mode 100644
index 6c79aa9..0000000
--- a/Foundation/GTMPath.m
+++ /dev/null
@@ -1,175 +0,0 @@
-//
-// GTMPath.m
-//
-// Copyright 2007-2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy
-// of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-//
-
-#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 {
- return [[[self alloc] initWithFullPath:fullPath] autorelease];
-}
-
-- (id)init {
- return [self initWithFullPath:nil];
-}
-
-- (id)initWithFullPath:(NSString *)fullPath {
- if ((self = [super init])) {
- fullPath_ = [[fullPath stringByResolvingSymlinksInPath] copy];
- if (![fullPath_ isAbsolutePath] || [self attributes] == nil) {
- [self release];
- return nil;
- }
- }
-
- return self;
-}
-
-- (void)dealloc {
- [fullPath_ release];
- [super dealloc];
-}
-
-- (NSString *)description {
- return [self fullPath];
-}
-
-- (NSString *)name {
- return [fullPath_ lastPathComponent];
-}
-
-- (GTMPath *)parent {
- if ([self isRoot]) return nil;
- NSString *parentPath = [fullPath_ stringByDeletingLastPathComponent];
- return [[self class] pathWithFullPath:parentPath];
-}
-
-- (BOOL)isDirectory {
- BOOL isDir = NO;
- BOOL exists = [[NSFileManager defaultManager]
- fileExistsAtPath:fullPath_ isDirectory:&isDir];
- return exists && isDir;
-}
-
-- (BOOL)isRoot {
- return [fullPath_ isEqualToString:@"/"];
-}
-
-- (NSDictionary *)attributes {
- NSFileManager *mgr = [NSFileManager defaultManager];
-#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
- NSDictionary *attributes = [mgr fileAttributesAtPath:fullPath_
- traverseLink:NO];
-#else
- NSDictionary *attributes = [mgr attributesOfItemAtPath:fullPath_
- error:NULL];
-#endif
- return attributes;
-}
-
-- (NSString *)fullPath {
- return [[fullPath_ copy] autorelease];
-}
-
-@end
-
-
-@implementation GTMPath (GTMPathGeneration)
-
-- (GTMPath *)createDirectoryName:(NSString *)name mode:(mode_t)mode {
- NSDictionary *attributes =
- [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:mode]
- forKey:NSFilePosixPermissions];
- return [self createDirectoryName:name attributes:attributes];
-}
-
-- (GTMPath *)createDirectoryName:(NSString *)name
- attributes:(NSDictionary *)attributes {
- if ([name length] == 0) return nil;
-
- // We first check to see if the requested directory alread exists by trying
- // to create a GTMPath from the desired new path string. Only if the path
- // doesn't already exist do we attempt to create it. If the path already
- // 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 && ![nascentPath isDirectory]) {
- return nil; // Return nil because the path exists, but it's not a dir
- }
-
- if (!nascentPath) {
- NSFileManager *mgr = [NSFileManager defaultManager];
-#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
- NSError *error = nil;
- BOOL created = [mgr createDirectoryAtPath:newPath
- withIntermediateDirectories:YES
- attributes:attributes
- error:&error];
-#else
- BOOL 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;
- }
-
- return nascentPath;
-}
-
-- (GTMPath *)createFileName:(NSString *)name mode:(mode_t)mode {
- NSDictionary *attributes =
- [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:mode]
- forKey:NSFilePosixPermissions];
- return [self createFileName:name attributes:attributes];
-}
-
-- (GTMPath *)createFileName:(NSString *)name
- attributes:(NSDictionary *)attributes {
- return [self createFileName:name attributes:attributes data:[NSData data]];
-}
-
-- (GTMPath *)createFileName:(NSString *)name
- attributes:(NSDictionary *)attributes
- data:(NSData *)data {
- if ([name length] == 0) return nil;
-
- // See createDirectoryName:attribute: for some high-level notes about what and
- // why this method does what it does.
- NSString *newPath = [fullPath_ stringByAppendingPathComponent:name];
- GTMPath *nascentPath = [GTMPath pathWithFullPath:newPath];
- if (nascentPath != nil && [nascentPath isDirectory]) {
- return nil; // Return nil because the path exists, but it's a dir
- }
-
- if (nascentPath == nil) {
- BOOL created = [[NSFileManager defaultManager]
- createFileAtPath:newPath
- contents:data
- attributes:attributes];
- nascentPath = created ? [GTMPath pathWithFullPath:newPath] : nil;
- }
-
- return nascentPath;
-}
-
-@end
-
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
diff --git a/Foundation/GTMPathTest.m b/Foundation/GTMPathTest.m
deleted file mode 100644
index dff1f02..0000000
--- a/Foundation/GTMPathTest.m
+++ /dev/null
@@ -1,239 +0,0 @@
-//
-// GTMPathTest.m
-//
-// Copyright 2007-2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy
-// of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-//
-
-#import "GTMSenTestCase.h"
-#import "GTMPath.h"
-#import "GTMNSFileHandle+UniqueName.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
- NSString *testDirectory_;
-}
-@end
-
-@implementation GTMPathTest
-
-- (void)setUp {
- NSFileManager *mgr = [NSFileManager defaultManager];
- testDirectory_
- = [[mgr gtm_createTemporaryDirectoryBasedOn:@"GTMPathTestXXXXXX"] retain];
-
- STAssertNotNil(testDirectory_, nil);
-}
-
-- (void)tearDown {
- // Make sure it's safe to remove this directory before nuking it.
- STAssertNotNil(testDirectory_, nil);
- STAssertNotEqualObjects(testDirectory_, @"/", nil);
-#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
- [[NSFileManager defaultManager] removeFileAtPath:testDirectory_ handler:nil];
-#else
- [[NSFileManager defaultManager] removeItemAtPath:testDirectory_ error:NULL];
-#endif
- [testDirectory_ release];
-}
-
-- (void)testBasicCreation {
- GTMPath *path = nil;
-
- path = [[[GTMPath alloc] init] autorelease];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"/"];
- STAssertNotNil(path, nil);
- STAssertNil([path parent], nil);
- STAssertTrue([path isRoot], nil);
- STAssertTrue([path isDirectory], nil);
- STAssertEqualObjects([path name], @"/", nil);
- STAssertEqualObjects([path fullPath], @"/", nil);
-}
-
-- (void)testRecursiveInitialization {
- GTMPath *path = nil;
-
- path = [GTMPath pathWithFullPath:nil];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@""];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"etc"];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"/"];
- STAssertNotNil(path, nil);
- STAssertNil([path parent], nil);
- STAssertTrue([path isRoot], nil);
- STAssertTrue([path isDirectory], nil);
- STAssertEqualObjects([path name], @"/", nil);
- STAssertEqualObjects([path fullPath], @"/", nil);
-
- path = [GTMPath pathWithFullPath:@"/etc"];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"etc", nil);
- STAssertEqualObjects([path fullPath], @"/etc", nil);
- STAssertTrue([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
- STAssertNotNil([path parent], nil);
- STAssertTrue([[path parent] isRoot], nil);
-
- path = [GTMPath pathWithFullPath:@"/etc/passwd"];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"passwd", nil);
- STAssertEqualObjects([path fullPath], @"/etc/passwd", nil);
- STAssertFalse([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
- STAssertNotNil([path parent], nil);
- STAssertFalse([[path parent] isRoot], nil);
- STAssertTrue([[path parent] isDirectory], nil);
- STAssertTrue([[[path parent] parent] isRoot], nil);
-
- STAssertTrue([[path description] length] > 1, nil);
-}
-
-- (void)testCreationWithNonExistentPath {
- GTMPath *path = nil;
-
- path = [GTMPath pathWithFullPath:@" "];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"/abcxyz"];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"/etc/foo"];
- STAssertNil(path, nil);
-
- path = [GTMPath pathWithFullPath:@"/foo/bar/baz"];
- STAssertNil(path, nil);
-}
-
-- (void)testDirectoryCreation {
- GTMPath *tmp = [GTMPath pathWithFullPath:testDirectory_];
- GTMPath *path = nil;
-
- NSString *fooPath = [[tmp fullPath] stringByAppendingPathComponent:@"foo"];
- path = [GTMPath pathWithFullPath:fooPath];
- STAssertNil(path, nil);
-
- path = [tmp createDirectoryName:@"foo" mode:0555];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- // filePosixPermissions has odd return types in different SDKs, so we use
- // STAssertTrue to avoid the macros type checks from choking us.
- STAssertTrue([[path attributes] filePosixPermissions] == 0555,
- @"got %o", (int)[[path attributes] filePosixPermissions]);
- STAssertTrue([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-
- // Trying to create a file where a dir already exists should fail
- path = [tmp createFileName:@"foo" mode:0555];
- STAssertNil(path, nil);
-
- // Calling create again should succeed
- path = [tmp createDirectoryName:@"foo" mode:0555];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0555,
- @"got %o", (int)[[path attributes] filePosixPermissions]);
- STAssertTrue([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-
- GTMPath *foo = [GTMPath pathWithFullPath:fooPath];
- STAssertNotNil(foo, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0555,
- @"got %o", (int)[[path attributes] filePosixPermissions]);
- STAssertTrue([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-}
-
-- (void)testFileCreation {
- GTMPath *tmp = [GTMPath pathWithFullPath:testDirectory_];
- GTMPath *path = nil;
-
- NSString *fooPath = [[tmp fullPath] stringByAppendingPathComponent:@"foo"];
- path = [GTMPath pathWithFullPath:fooPath];
- STAssertNil(path, nil);
-
- path = [tmp createFileName:@"foo" mode:0555];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil);
- STAssertFalse([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-
- // Trying to create a dir where a file already exists should fail.
- path = [tmp createDirectoryName:@"foo" mode:0555];
- STAssertNil(path, nil);
-
- // Calling create again should succeed
- path = [tmp createFileName:@"foo" mode:0555];
- STAssertNotNil(path, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil);
- STAssertFalse([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-
- GTMPath *foo = [GTMPath pathWithFullPath:fooPath];
- STAssertNotNil(foo, nil);
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil);
- STAssertFalse([path isDirectory], nil);
- STAssertFalse([path isRoot], nil);
-
- // Make sure we can't create a file/directory rooted off of |foo|, since it's
- // not a directory.
- path = [foo createFileName:@"bar" mode:0555];
- STAssertNil(path, nil);
- path = [foo createDirectoryName:@"bar" mode:0555];
- STAssertNil(path, nil);
-}
-
-- (void)testHierarchyCreation {
- GTMPath *tmp = [GTMPath pathWithFullPath:testDirectory_];
- NSString *fooPath = [[tmp fullPath] stringByAppendingPathComponent:@"foo"];
- GTMPath *path = [GTMPath pathWithFullPath:fooPath];
- STAssertNil(path, nil);
-
- path = [[[tmp createDirectoryName:@"foo" mode:0755]
- createDirectoryName:@"bar" mode:0756]
- createDirectoryName:@"baz" mode:0757];
- STAssertNotNil(path, nil);
-
- // Check "baz"
- STAssertEqualObjects([path name], @"baz", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0757, nil);
-
- // Check "bar"
- path = [path parent];
- STAssertEqualObjects([path name], @"bar", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0756, nil);
-
- // Check "foo"
- path = [path parent];
- STAssertEqualObjects([path name], @"foo", nil);
- STAssertTrue([[path attributes] filePosixPermissions] == 0755, nil);
-}
-
-@end
-
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5