Add new init method

This commit is contained in:
Gregory John Casamento 2019-08-05 14:37:58 -04:00
parent 52459ae2aa
commit 69168d3661
2 changed files with 74 additions and 11 deletions

View file

@ -200,6 +200,8 @@ typedef uint32_t OSType;
#define OSTYPE_DECLARED
#endif
DEFINE_BLOCK_TYPE(GSDirEnumErrorHandler, BOOL, NSURL*, NSError*);
enum _NSDirectoryEnumerationOptions
{
NSDirectoryEnumerationSkipsSubdirectoryDescendants = 1L << 0,
@ -355,7 +357,6 @@ typedef NSUInteger NSDirectoryEnumerationOptions;
/**
* Enumerate over the contents of a directory.
*/
DEFINE_BLOCK_TYPE(GSDirEnumErrorHandler, BOOL, NSURL*, NSError*);
- (NSDirectoryEnumerator *)enumeratorAtURL: (NSURL *)url
includingPropertiesForKeys: (NSArray *)keys
options: (NSDirectoryEnumerationOptions)mask
@ -564,11 +565,13 @@ DEFINE_BLOCK_TYPE(GSDirEnumErrorHandler, BOOL, NSURL*, NSError*);
NSString *_topPath;
NSString *_currentFilePath;
NSFileManager *_mgr;
GSDirEnumErrorHandler _errorHandler;
struct _NSDirectoryEnumeratorFlags // tag for objc++ w/gcc 4.6
{
BOOL isRecursive: 1;
BOOL isFollowing: 1;
BOOL justContents: 1;
BOOL skipHidden: 1;
} _flags;
#endif
#if GS_NONFRAGILE

View file

@ -179,6 +179,17 @@
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
for: (NSFileManager*)mgr;
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
skipHidden: (BOOL)skipHidden
errorHandler: (GSDirEnumErrorHandler) handler
for: (NSFileManager*)mgr;
- (void) _setSkipHidden: (BOOL)flag;
- (void) _setErrorHandler: (GSDirEnumErrorHandler) handler;
@end
/*
@ -809,7 +820,27 @@ static NSStringEncoding defaultEncoding;
options: (NSDirectoryEnumerationOptions)mask
errorHandler: (GSDirEnumErrorHandler)handler
{
return nil;
NSDirectoryEnumerator *direnum;
NSString *path;
DESTROY(_lastError);
if (![[url scheme] isEqualToString: @"file"])
{
return nil;
}
path = [url path];
direnum = [[NSDirectoryEnumerator alloc]
initWithDirectoryPath: path
recurseIntoSubdirectories: !(mask & NSDirectoryEnumerationSkipsSubdirectoryDescendants)
followSymlinks: NO
justContents: NO
skipHidden: (mask & NSDirectoryEnumerationSkipsHiddenFiles)
errorHandler: handler
for: self];
return direnum;
}
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error: (NSError**)error
@ -2490,18 +2521,22 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
}
}
/**
* Initialize instance to enumerate contents at path, which should be a
* directory and can be specified in relative or absolute, and may include
* Unix conventions like '<code>~</code>' for user home directory, which will
* be appropriately converted on Windoze systems. The justContents flag, if
* set, is equivalent to recurseIntoSubdirectories = NO and followSymlinks =
* NO, but the implementation will be made more efficient.
*/
- (void) _setSkipHidden: (BOOL)flag
{
_flags.skipHidden = flag;
}
- (void) _setErrorHandler: (GSDirEnumErrorHandler) handler
{
_errorHandler = handler;
}
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
skipHidden: (BOOL)skipHidden
errorHandler: (GSDirEnumErrorHandler) handler
for: (NSFileManager*)mgr
{
if (nil != (self = [super init]))
@ -2518,7 +2553,9 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
_flags.isRecursive = recurse;
_flags.isFollowing = follow;
_flags.justContents = justContents;
_flags.skipHidden = skipHidden;
_errorHandler = handler;
_topPath = [[NSString alloc] initWithString: path];
localPath = [_mgr fileSystemRepresentationWithPath: path];
@ -2558,6 +2595,29 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
return self;
}
/**
* Initialize instance to enumerate contents at path, which should be a
* directory and can be specified in relative or absolute, and may include
* Unix conventions like '<code>~</code>' for user home directory, which will
* be appropriately converted on Windoze systems. The justContents flag, if
* set, is equivalent to recurseIntoSubdirectories = NO and followSymlinks =
* NO, but the implementation will be made more efficient.
*/
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
for: (NSFileManager*)mgr
{
return [self initWithDirectoryPath: path
recurseIntoSubdirectories: recurse
followSymlinks: follow
justContents: justContents
skipHidden: NO
errorHandler: NULL
for: mgr];
}
- (void) dealloc
{
GSIArrayEmpty(_stack);