mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Add simple (files only and no keys handling) implementation of 10.6 method contentsOfDirectoryAtURL
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38987 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
529bc2bd33
commit
2ec70cee86
3 changed files with 92 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2015-09-16 Riccardo Mottola <rm@gnu.org>
|
||||||
|
|
||||||
|
* Headers/Foundation/NSFileManager.h
|
||||||
|
* Source/NSFileManager.m
|
||||||
|
Add simple (files only and no keys handling) implementation of 10.6 method contentsOfDirectoryAtURL.
|
||||||
|
|
||||||
2015-09-08 Niels Grewe <niels.grewe@halbordnung.de>
|
2015-09-08 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* Source/NSPropertyList.m: Fix writing base64 data.
|
* Source/NSPropertyList.m: Fix writing base64 data.
|
||||||
|
|
|
@ -198,6 +198,13 @@ typedef uint32_t OSType;
|
||||||
#define OSTYPE_DECLARED
|
#define OSTYPE_DECLARED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum : NSUInteger
|
||||||
|
{
|
||||||
|
NSDirectoryEnumerationSkipsSubdirectoryDescendants = 1L << 0,
|
||||||
|
NSDirectoryEnumerationSkipsPackageDescendants = 1L << 1,
|
||||||
|
NSDirectoryEnumerationSkipsHiddenFiles = 1L << 2
|
||||||
|
} NSDirectoryEnumerationOptions;
|
||||||
|
|
||||||
@interface NSFileManager : NSObject
|
@interface NSFileManager : NSObject
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSFileManager)
|
#if GS_EXPOSE(NSFileManager)
|
||||||
|
@ -299,9 +306,23 @@ typedef uint32_t OSType;
|
||||||
- (BOOL) contentsEqualAtPath: (NSString*)path1
|
- (BOOL) contentsEqualAtPath: (NSString*)path1
|
||||||
andPath: (NSString*)path2;
|
andPath: (NSString*)path2;
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||||
|
/**
|
||||||
|
* Returns an array of NSURL of the contents of the specified directory. <br>
|
||||||
|
* The listing is shallow and does not recurse into subdirectories.
|
||||||
|
* The special files '.' and '..' are excluded but it can return hidden files. <br>
|
||||||
|
* The only <i>mask</i> option supported is NSDirectoryEnumerationSkipsHiddenFiles.<br>
|
||||||
|
* The current implementation handles only files and property keys are ignored.
|
||||||
|
*/
|
||||||
|
- (NSArray*) contentsOfDirectoryAtURL:(NSURL*)url
|
||||||
|
includingPropertiesForKeys:(NSArray*)keys
|
||||||
|
options:(NSDirectoryEnumerationOptions)mask
|
||||||
|
error:(NSError **)error;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||||
/**
|
/**
|
||||||
* Returns an array of the contents of the specified directory.<br />
|
* Returns an array of NSStrings of the contents of the specified directory.<br />
|
||||||
* The listing does <strong>not</strong> recursively list subdirectories.<br />
|
* The listing does <strong>not</strong> recursively list subdirectories.<br />
|
||||||
* The special files '.' and '..' are not listed.<br />
|
* The special files '.' and '..' are not listed.<br />
|
||||||
* Indicates an error by returning nil (eg. if path is not a directory or
|
* Indicates an error by returning nil (eg. if path is not a directory or
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
NSFileManager.m
|
NSFileManager.m
|
||||||
|
|
||||||
Copyright (C) 1997-2002 Free Software Foundation, Inc.
|
Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
|
Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
|
||||||
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
||||||
|
@ -693,6 +693,69 @@ static NSStringEncoding defaultEncoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray*) contentsOfDirectoryAtURL:(NSURL*)url
|
||||||
|
includingPropertiesForKeys:(NSArray*)keys
|
||||||
|
options:(NSDirectoryEnumerationOptions)mask
|
||||||
|
error:(NSError **)error
|
||||||
|
{
|
||||||
|
NSArray *result;
|
||||||
|
NSDirectoryEnumerator *direnum;
|
||||||
|
NSString *path;
|
||||||
|
|
||||||
|
DESTROY(_lastError);
|
||||||
|
|
||||||
|
if (![[url scheme] isEqualToString:@"file"])
|
||||||
|
return nil;
|
||||||
|
path = [url path];
|
||||||
|
|
||||||
|
direnum = [[NSDirectoryEnumerator alloc]
|
||||||
|
initWithDirectoryPath: path
|
||||||
|
recurseIntoSubdirectories: NO
|
||||||
|
followSymlinks: NO
|
||||||
|
justContents: NO
|
||||||
|
for: self];
|
||||||
|
|
||||||
|
/* we make an array of NSURLs */
|
||||||
|
result = nil;
|
||||||
|
if (nil != direnum)
|
||||||
|
{
|
||||||
|
IMP nxtImp;
|
||||||
|
NSMutableArray *urlArray;
|
||||||
|
NSString *tempPath;
|
||||||
|
|
||||||
|
|
||||||
|
nxtImp = [direnum methodForSelector: @selector(nextObject)];
|
||||||
|
|
||||||
|
urlArray = [NSMutableArray arrayWithCapacity:128];
|
||||||
|
while ((tempPath = (*nxtImp)(direnum, @selector(nextObject))) != nil)
|
||||||
|
{
|
||||||
|
NSURL *tempURL;
|
||||||
|
NSString *lastComponent;
|
||||||
|
|
||||||
|
tempURL = [NSURL fileURLWithPath:tempPath];
|
||||||
|
lastComponent = [tempPath lastPathComponent];
|
||||||
|
|
||||||
|
/* we purge files beginning with . */
|
||||||
|
if (!((mask & NSDirectoryEnumerationSkipsHiddenFiles) && [lastComponent hasPrefix:@"."]))
|
||||||
|
[urlArray addObject:tempURL];
|
||||||
|
}
|
||||||
|
RELEASE(direnum);
|
||||||
|
|
||||||
|
if ([urlArray count] > 0)
|
||||||
|
result = [NSArray arrayWithArray:urlArray];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error != NULL)
|
||||||
|
{
|
||||||
|
if (nil == result)
|
||||||
|
{
|
||||||
|
*error = [self _errorFrom: path to: nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error: (NSError**)error
|
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error: (NSError**)error
|
||||||
{
|
{
|
||||||
NSArray *result;
|
NSArray *result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue