summary refs log tree commit diff
path: root/src/libcore/os.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/os.rs')
-rw-r--r--src/libcore/os.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 269744296f8..9af5f1f6560 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -34,6 +34,7 @@ export homedir, list_dir, list_dir_path, path_is_dir, path_exists,
        copy_file;
 export last_os_error;
 export set_exit_status;
+export walk_dir;
 
 // FIXME: move these to str perhaps?
 export as_c_charp, fill_charp_buf;
@@ -387,7 +388,34 @@ fn homedir() -> option<path> {
     }
 }
 
+#[doc = "Recursively walk a directory structure"]
+fn walk_dir(p: path, f: fn(path) -> bool) {
 
+    walk_dir_(p, f);
+
+    fn walk_dir_(p: path, f: fn(path) -> bool) -> bool {
+        let mut keepgoing = true;
+        list_dir(p).each {|q|
+            let path = path::connect(p, q);
+            if !f(path) {
+                keepgoing = false;
+                false
+            } else {
+                if path_is_dir(path) {
+                    if !walk_dir_(path, f) {
+                        keepgoing = false;
+                        false
+                    } else {
+                        true
+                    }
+                } else {
+                    true
+                }
+            }
+        }
+        ret keepgoing;
+    }
+}
 
 #[doc = "Indicates whether a path represents a directory"]
 fn path_is_dir(p: path) -> bool {