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:
rmottola 2015-09-16 00:53:30 +00:00
parent 529bc2bd33
commit 2ec70cee86
3 changed files with 92 additions and 2 deletions

View file

@ -1,7 +1,7 @@
/**
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: 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 *result;