Author: mlytwyn
Date: Tue Dec 1 18:04:16 2015
New Revision: 39203
URL: http://svn.gna.org/viewcvs/gnustep?rev=39203&view=rev
Log:
Add 'contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:' to
NSFileManager - DOES NOT PROCESS properties keys yet
Modified:
libs/base/branches/gnustep_testplant_branch/Headers/Foundation/NSFileManager.h
libs/base/branches/gnustep_testplant_branch/Source/NSFileManager.m
Modified:
libs/base/branches/gnustep_testplant_branch/Headers/Foundation/NSFileManager.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Headers/Foundation/NSFileManager.h?rev=39203&r1=39202&r2=39203&view=diff
==============================================================================
---
libs/base/branches/gnustep_testplant_branch/Headers/Foundation/NSFileManager.h
(original)
+++
libs/base/branches/gnustep_testplant_branch/Headers/Foundation/NSFileManager.h
Tue Dec 1 18:04:16 2015
@@ -197,6 +197,20 @@
typedef uint32_t OSType;
#define OSTYPE_DECLARED
#endif
+
+typedef enum {
+ /* NSDirectoryEnumerationSkipsSubdirectoryDescendants causes the
NSDirectoryEnumerator to perform a shallow enumeration and not descend into
directories it encounters.
+ */
+ NSDirectoryEnumerationSkipsSubdirectoryDescendants = 1UL << 0,
+
+ /* NSDirectoryEnumerationSkipsPackageDescendants will cause the
NSDirectoryEnumerator to not descend into packages.
+ */
+ NSDirectoryEnumerationSkipsPackageDescendants = 1UL << 1,
+
+ /* NSDirectoryEnumerationSkipsHiddenFiles causes the NSDirectoryEnumerator
to not enumerate hidden files.
+ */
+ NSDirectoryEnumerationSkipsHiddenFiles = 1UL << 2
+} NSDirectoryEnumerationOptions;
@interface NSFileManager : NSObject
{
@@ -312,6 +326,13 @@
* it can't be read for some reason).
*/
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error:
(NSError**)error;
+#endif
+
+#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
+- (NSArray*)contentsOfDirectoryAtURL:(NSURL*)url
+ includingPropertiesForKeys:(NSArray*)keys
+ options:(NSDirectoryEnumerationOptions)mask
+ error:(NSError**)error;
#endif
- (BOOL) copyPath: (NSString*)source
@@ -348,7 +369,7 @@
*/
- (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path;
- (NSDictionary*) fileAttributesAtPath: (NSString*)path
- traverseLink: (BOOL)flag;
+ traverseLink: (BOOL)flag;
/**
* Returns YES if a file (or directory etc) exists at the specified path.
Modified: libs/base/branches/gnustep_testplant_branch/Source/NSFileManager.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/NSFileManager.m?rev=39203&r1=39202&r2=39203&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Source/NSFileManager.m
(original)
+++ libs/base/branches/gnustep_testplant_branch/Source/NSFileManager.m Tue Dec
1 18:04:16 2015
@@ -769,6 +769,82 @@
}
return result;
+}
+
+- (NSArray*)contentsOfDirectoryAtURL:(NSURL*)url
+ includingPropertiesForKeys:(NSArray*)keys
+ options:(NSDirectoryEnumerationOptions)mask
+ error:(NSError**)errorptr;
+{
+ NSMutableArray *dirurls = [NSMutableArray array];
+ BOOL isDir = NO;
+
+ if (url == nil)
+ {
+ NSWarnMLog(@"URL is nil");
+ }
+ else if ([self fileExistsAtPath:[url path] isDirectory:&isDir] == NO)
+ {
+ NSWarnMLog(@"URL path does not exists");
+ }
+ else if (isDir == NO)
+ {
+ NSWarnMLog(@"URL path is not a directory");
+ }
+ else
+ {
+ NSError *error = nil;
+ NSString *dirpath = [url path];
+ NSArray *contents = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:dirpath error:&error];
+
+ if (error)
+ {
+ NSWarnMLog(@"error: %@", error);
+
+ // Return possible error...
+ if (errorptr != NULL)
+ *errorptr = error;
+ }
+ else
+ {
+ NSEnumerator *iter = [contents objectEnumerator];
+ NSString *filename = nil;
+
+ // Iterate and create NSURL's for each path...
+ while ((filename = [iter nextObject]))
+ {
+ NSString *filepath = [dirpath
stringByAppendingPathComponent:filename];
+ NSURL *url = [NSURL fileURLWithPath:filepath];
+#if 0
+ NSEnumerator *keyiter = [keys objectEnumerator];
+ NSString *key = nil;
+#endif
+
+ // Add URL...
+ [dirurls addObject:url];
+
+#if 0
+ // TODO: Resource keys not currently processed...
+ // Preload resources for requested keys...
+ while ((key = [keyiter nextObject]))
+ {
+ // Just ask for the property key - NSURL will cache...
+ NSDictionary *fileattr = [self fileAttributesAtPath:filepath
traverseLink:NO];
+ NSEnumerator *attrkeyiter = [fileattr keyEnumerator];
+ NSString *attrkey = nil;
+
+ while ((attrkey = [attrkeyiter nextObject]))
+ {
+ [url setResourceValue:[fileattr objectForKey:attrkey]
forKey:attrkey];
+ }
+ }
+#endif
+ }
+ }
+ }
+
+ // Return an immutable copy...
+ return([[dirurls copy] autorelease]);
}
/**
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs