Author: rmottola
Date: Wed Sep 16 02:53:30 2015
New Revision: 38987

URL: http://svn.gna.org/viewcvs/gnustep?rev=38987&view=rev
Log:
Add simple (files only and no keys handling) implementation of 10.6 method 
contentsOfDirectoryAtURL

Modified:
    libs/base/trunk/ChangeLog
    libs/base/trunk/Headers/Foundation/NSFileManager.h
    libs/base/trunk/Source/NSFileManager.m

Modified: libs/base/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38987&r1=38986&r2=38987&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog   (original)
+++ libs/base/trunk/ChangeLog   Wed Sep 16 02:53:30 2015
@@ -1,3 +1,9 @@
+2015-09-16 Riccardo Mottola <[email protected]>
+
+       * 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 <[email protected]>
 
        * Source/NSPropertyList.m: Fix writing base64 data.

Modified: libs/base/trunk/Headers/Foundation/NSFileManager.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/Foundation/NSFileManager.h?rev=38987&r1=38986&r2=38987&view=diff
==============================================================================
--- libs/base/trunk/Headers/Foundation/NSFileManager.h  (original)
+++ libs/base/trunk/Headers/Foundation/NSFileManager.h  Wed Sep 16 02:53:30 2015
@@ -198,6 +198,13 @@
 #define OSTYPE_DECLARED
 #endif
 
+typedef enum : NSUInteger
+  {
+    NSDirectoryEnumerationSkipsSubdirectoryDescendants = 1L << 0,
+    NSDirectoryEnumerationSkipsPackageDescendants = 1L << 1,
+    NSDirectoryEnumerationSkipsHiddenFiles = 1L << 2
+  } NSDirectoryEnumerationOptions; 
+  
 @interface NSFileManager : NSObject
 {
 #if    GS_EXPOSE(NSFileManager)
@@ -299,9 +306,23 @@
 - (BOOL) contentsEqualAtPath: (NSString*)path1
                     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)
 /**
- * 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 special files '.' and '..' are not listed.<br />
  * Indicates an error by returning nil (eg. if path is not a directory or

Modified: libs/base/trunk/Source/NSFileManager.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSFileManager.m?rev=38987&r1=38986&r2=38987&view=diff
==============================================================================
--- libs/base/trunk/Source/NSFileManager.m      (original)
+++ libs/base/trunk/Source/NSFileManager.m      Wed Sep 16 02:53:30 2015
@@ -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 <[email protected]>
    Author: Ovidiu Predescu <[email protected]>
@@ -691,6 +691,69 @@
     {
       return YES;
     }
+}
+
+- (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


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to