[f-spot] allow RecursiveFileEnumerator to enumerate a single file



commit 631d084a33694696cd75729642842afd47488e08
Author: Mike Gemünde <mike gemuende de>
Date:   Wed May 19 16:39:48 2010 +0200

    allow RecursiveFileEnumerator to enumerate a single file
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619096

 src/Utils/RecursiveFileEnumerator.cs |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/src/Utils/RecursiveFileEnumerator.cs b/src/Utils/RecursiveFileEnumerator.cs
index 090c10c..c7453ce 100644
--- a/src/Utils/RecursiveFileEnumerator.cs
+++ b/src/Utils/RecursiveFileEnumerator.cs
@@ -22,14 +22,27 @@ namespace FSpot.Utils
 
         IEnumerable<File> ScanForFiles (File root)
         {
-            var enumerator = root.EnumerateChildren ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+            var root_info = root.QueryInfo ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+
+            if (root_info.FileType == FileType.Regular) {
+                yield return root;
+            } else if (root_info.FileType == FileType.Directory) {
+                foreach (var child in ScanDirectoryForFiles (root)) {
+                    yield return child;
+                }
+            }
+        }
+
+        IEnumerable<File> ScanDirectoryForFiles (File root_dir)
+        {
+            var enumerator = root_dir.EnumerateChildren ("standard::name,standard::type", FileQueryInfoFlags.None, null);
             foreach (FileInfo info in enumerator) {
-                File file = root.GetChild (info.Name);
+                File file = root_dir.GetChild (info.Name);
                 
                 if (info.FileType == FileType.Regular) {
                     yield return file;
                 } else if (info.FileType == FileType.Directory && recurse) {
-                    foreach (var child in ScanForFiles (file)) {
+                    foreach (var child in ScanDirectoryForFiles (file)) {
                         yield return child;
                     }
                 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]