]> git.lizzy.rs Git - rust.git/commitdiff
Fixing issue 1919. list_dir is the more general version that returns a vector with...
authorJonathan Sternberg <jonathansternberg@gmail.com>
Sun, 1 Apr 2012 15:39:17 +0000 (11:39 -0400)
committerJonathan Sternberg <jonathansternberg@gmail.com>
Sun, 1 Apr 2012 15:39:17 +0000 (11:39 -0400)
src/cargo/cargo.rs
src/compiletest/compiletest.rs
src/fuzzer/fuzzer.rs
src/libcore/os.rs
src/rustc/util/filesearch.rs

index 51edc90589acd86a86717410f4014978e213ce2a..9cad4bb3f94b8ff272ff5ddce9fd738b49c6f4eb 100644 (file)
@@ -434,7 +434,7 @@ fn for_each_package(c: cargo, b: fn(source, package)) {
 
 // Runs all programs in directory <buildpath>
 fn run_programs(buildpath: str) {
-    let newv = os::list_dir(buildpath);
+    let newv = os::list_dir_path(buildpath);
     for ct: str in newv {
         run::run_program(ct, []);
     }
@@ -471,7 +471,7 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
       none { ret; }
       some(bp) { bp }
     };
-    let newv = os::list_dir(buildpath);
+    let newv = os::list_dir_path(buildpath);
     let exec_suffix = os::exe_suffix();
     for ct: str in newv {
         if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
@@ -524,7 +524,7 @@ fn rustc_sysroot() -> str {
 fn install_source(c: cargo, path: str) {
     #debug("source: %s", path);
     os::change_dir(path);
-    let contents = os::list_dir(".");
+    let contents = os::list_dir_path(".");
 
     #debug("contents: %s", str::connect(contents, ", "));
 
index ed159d6a073b03e2a079b798c37f4ab7af015bef..0ea7fecda75c11f051bc5258ee11ee5506cdeeb8 100644 (file)
@@ -127,7 +127,7 @@ fn test_opts(config: config) -> test::test_opts {
 fn make_tests(config: config) -> [test::test_desc] {
     #debug("making tests from %s", config.src_base);
     let mut tests = [];
-    for file: str in os::list_dir(config.src_base) {
+    for file: str in os::list_dir_path(config.src_base) {
         let file = file;
         #debug("inspecting file %s", file);
         if is_test(config, file) {
index 70fe1afa876163916084e74cc1af9b6c92a12dec..87dece998b0dda63569e8a4cdf5d62af51dcc7cf 100644 (file)
@@ -25,7 +25,7 @@ fn find_rust_files(&files: [str], path: str) {
     } else if os::path_is_dir(path)
         && !contains(path, "compile-fail")
         && !contains(path, "build") {
-        for p in os::list_dir(path) {
+        for p in os::list_dir_path(path) {
             find_rust_files(files, p);
         }
     }
index 8d9cd47fdf8bc52486b8f91e312e582a24858b4b..d7e4af2a15acd46ff1e053e4b95401e912faa89c 100644 (file)
@@ -29,8 +29,8 @@
 export env, getenv, setenv, fdopen, pipe;
 export getcwd, dll_filename, self_exe_path;
 export exe_suffix, dll_suffix, sysname;
-export homedir, list_dir, path_is_dir, path_exists, make_absolute,
-       make_dir, remove_dir, change_dir, remove_file;
+export homedir, list_dir, list_dir_path, path_is_dir, path_exists,
+       make_absolute, make_dir, remove_dir, change_dir, remove_file;
 
 // FIXME: move these to str perhaps?
 export as_c_charp, fill_charp_buf;
@@ -452,26 +452,37 @@ fn list_dir(p: path) -> [str] {
     #[cfg(target_os = "linux")]
     #[cfg(target_os = "macos")]
     #[cfg(target_os = "freebsd")]
-    fn star() -> str { "" }
+    fn star(p: str) -> str { p }
 
     #[cfg(target_os = "win32")]
-    fn star() -> str { "*" }
+    fn star(p: str) -> str {
+        let pl = str::len(p);
+        if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
+                        ** p[pl - 1u] as char != path::consts::alt_path_sep) {
+            p + path::path_sep() + "*"
+        } else {
+            p + "*"
+        }
+    }
 
+    rustrt::rust_list_files(star(p)).filter {|filename|
+        !str::eq(filename, ".") || !str::eq(filename, "..")
+    }
+}
+
+#[doc = "
+Lists the contents of a directory
+
+This version prepends each entry with the directory.
+"]
+fn list_dir_path(p: path) -> [str] {
     let mut p = p;
     let pl = str::len(p);
     if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
                     && p[pl - 1u] as char != path::consts::alt_path_sep) {
         p += path::path_sep();
     }
-    let mut full_paths: [str] = [];
-    for vec::each(rustrt::rust_list_files(p + star())) {|filename|
-        if !str::eq(filename, ".") {
-            if !str::eq(filename, "..") {
-                full_paths += [p + filename];
-            }
-        }
-    }
-    ret full_paths;
+    os::list_dir(p).map {|f| p + f}
 }
 
 #[doc = "Removes a directory at the specified path"]
@@ -750,4 +761,4 @@ fn path_exists() {
         assert (!os::path_exists("test/nonexistent-bogus-path"));
     }
 
-}
\ No newline at end of file
+}
index ac535f39bef6ef4fb0f077acc2883ebba512dfe8..75327597ce92959a4d684f828aacae7b2df7a46d 100644 (file)
@@ -69,7 +69,7 @@ fn get_target_lib_file_path(file: path) -> path {
 fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> {
     for lib_search_path in filesearch.lib_search_paths() {
         #debug("searching %s", lib_search_path);
-        for path in os::list_dir(lib_search_path) {
+        for path in os::list_dir_path(lib_search_path) {
             #debug("testing %s", path);
             let maybe_picked = pick(path);
             if option::is_some(maybe_picked) {