From 9689bbaadfb2e93fdce63ced942daab7e3e84423 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Sun, 15 Sep 2002 07:51:29 +0000 Subject: [PATCH] Implement new methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14441 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 ++ Headers/gnustep/base/NSFileManager.h | 78 +++++++++++----------------- Source/NSFileManager.m | 33 +++++++++++- 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58e8d6cd2..53b0b78f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-09-15 Richard Frith-Macdonald + + * Source/NSFileManager.m: MacOS-X ([componentsToDisplayForPath:]) and + ([displayNameAtPath:]) methods imnplemented. + 2002-09-13 Adam Fedor * Source/cifframe.m (cifframe_guess_struct_size): Recurse if diff --git a/Headers/gnustep/base/NSFileManager.h b/Headers/gnustep/base/NSFileManager.h index 9d97215f3..084a86dc4 100644 --- a/Headers/gnustep/base/NSFileManager.h +++ b/Headers/gnustep/base/NSFileManager.h @@ -47,65 +47,51 @@ NSString *_lastError; } -// Getting the default manager + (NSFileManager*) defaultManager; -// Directory operations - (BOOL) changeCurrentDirectoryPath: (NSString*)path; +- (BOOL) changeFileAttributes: (NSDictionary*)attributes + atPath: (NSString*)path; +- (NSArray*) componentsToDisplayForPath: (NSString*)path; +- (NSData*) contentsAtPath: (NSString*)path; +- (BOOL) contentsEqualAtPath: (NSString*)path1 + andPath: (NSString*)path2; +- (BOOL) copyPath: (NSString*)source + toPath: (NSString*)destination + handler: (id)handler; - (BOOL) createDirectoryAtPath: (NSString*)path attributes: (NSDictionary*)attributes; +- (BOOL) createFileAtPath: (NSString*)path + contents: (NSData*)contents + attributes: (NSDictionary*)attributes; +- (BOOL) createSymbolicLinkAtPath: (NSString*)path + pathContent: (NSString*)otherPath; - (NSString*) currentDirectoryPath; - -// File operations -- (BOOL) copyPath: (NSString*)source +- (NSArray*) directoryContentsAtPath: (NSString*)path; +- (NSString*) displayNameAtPath: (NSString*)path; +- (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path; +- (NSDictionary*) fileAttributesAtPath: (NSString*)path + traverseLink: (BOOL)flag; +- (BOOL) fileExistsAtPath: (NSString*)path; +- (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory; +- (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path; +- (const char*) fileSystemRepresentationWithPath: (NSString*)path; +- (BOOL) isExecutableFileAtPath: (NSString*)path; +- (BOOL) isDeletableFileAtPath: (NSString*)path; +- (BOOL) isReadableFileAtPath: (NSString*)path; +- (BOOL) isWritableFileAtPath: (NSString*)path; +- (BOOL) linkPath: (NSString*)source toPath: (NSString*)destination handler: (id)handler; - (BOOL) movePath: (NSString*)source toPath: (NSString*)destination handler: (id)handler; -- (BOOL) linkPath: (NSString*)source - toPath: (NSString*)destination - handler: (id)handler; +- (NSString*) pathContentOfSymbolicLinkAtPath: (NSString*)path; - (BOOL) removeFileAtPath: (NSString*)path handler: (id)handler; -- (BOOL) createFileAtPath: (NSString*)path - contents: (NSData*)contents - attributes: (NSDictionary*)attributes; - -// Getting and comparing file contents -- (NSData*) contentsAtPath: (NSString*)path; -- (BOOL) contentsEqualAtPath: (NSString*)path1 - andPath: (NSString*)path2; - -// Detemining access to files -- (BOOL) fileExistsAtPath: (NSString*)path; -- (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory; -- (BOOL) isReadableFileAtPath: (NSString*)path; -- (BOOL) isWritableFileAtPath: (NSString*)path; -- (BOOL) isExecutableFileAtPath: (NSString*)path; -- (BOOL) isDeletableFileAtPath: (NSString*)path; - -// Getting and setting attributes -- (NSDictionary*) fileAttributesAtPath: (NSString*)path - traverseLink: (BOOL)flag; -- (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path; -- (BOOL) changeFileAttributes: (NSDictionary*)attributes - atPath: (NSString*)path; - -// Discovering directory contents -- (NSArray*) directoryContentsAtPath: (NSString*)path; -- (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path; -- (NSArray*) subpathsAtPath: (NSString*)path; - -// Symbolic-link operations -- (BOOL) createSymbolicLinkAtPath: (NSString*)path - pathContent: (NSString*)otherPath; -- (NSString*) pathContentOfSymbolicLinkAtPath: (NSString*)path; - -// Converting file-system representations -- (const char*) fileSystemRepresentationWithPath: (NSString*)path; - (NSString*) stringWithFileSystemRepresentation: (const char*)string length: (unsigned int)len; +- (NSArray*) subpathsAtPath: (NSString*)path; @end /* NSFileManager */ @@ -132,17 +118,13 @@ } _flags; } -// Initializing - (id) initWithDirectoryPath: (NSString*)path recurseIntoSubdirectories: (BOOL)recurse followSymlinks: (BOOL)follow justContents: (BOOL)justContents; -// Getting attributes - (NSDictionary*) directoryAttributes; - (NSDictionary*) fileAttributes; - -// Skipping subdirectories - (void) skipDescendents; @end /* NSDirectoryEnumerator */ diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 2125c5e4a..d7e2c5237 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -1238,8 +1238,25 @@ static NSFileManager* defaultManager = nil; return allOk; } -// Discovering directory contents +/** + * Returns an array of path components suitably modified for display + * to the end user. This modification may render the returned strings + * unusable for path manipulation, so you should work with two arrays ... + * one returned by this method (for display tio the user), and a + * parallel one returned by [NSString-pathComponents] (for path + * manipulation). + */ +- (NSArray*) componentsToDisplayForPath: (NSString*)path +{ + return [path pathComponents]; +} +/** + * Returns an array of the contents of the specified directory.
+ * The listing does not recursively list subdirectories.
+ * The special files '.' and '..' are not listed.
+ * Returns nil if path is not a directory (or it can't be read for some reason). + */ - (NSArray*) directoryContentsAtPath: (NSString*)path { NSDirectoryEnumerator *direnum; @@ -1277,6 +1294,20 @@ static NSFileManager* defaultManager = nil; return content; } +/** + * Returns the name of the file or directory at path. Converts it into + * a format for display to an end user. This may render it unusable as + * part of a file/path name.
+ * For instance, if a user has elected not to see file extensions, this + * method may return filenames with the extension removed.
+ * The default operation is to return the result of calling + * [NSString-lastPathComponent] on the path. + */ +- (NSString*) displayNameAtPath: (NSString*)path +{ + return [path lastPathComponent]; +} + - (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path { return AUTORELEASE([[NSDirectoryEnumerator alloc]