Skip to content

Commit 252086c

Browse files
committed
Merge pull request #2099 from jsternberg/master
os::list_dir to return only the contents of the directory
2 parents 9d5c20e + 3a0477c commit 252086c

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

src/cargo/cargo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ fn for_each_package(c: cargo, b: fn(source, package)) {
434434

435435
// Runs all programs in directory <buildpath>
436436
fn run_programs(buildpath: str) {
437-
let newv = os::list_dir(buildpath);
437+
let newv = os::list_dir_path(buildpath);
438438
for ct: str in newv {
439439
run::run_program(ct, []);
440440
}
@@ -471,7 +471,7 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
471471
none { ret; }
472472
some(bp) { bp }
473473
};
474-
let newv = os::list_dir(buildpath);
474+
let newv = os::list_dir_path(buildpath);
475475
let exec_suffix = os::exe_suffix();
476476
for ct: str in newv {
477477
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
@@ -524,7 +524,7 @@ fn rustc_sysroot() -> str {
524524
fn install_source(c: cargo, path: str) {
525525
#debug("source: %s", path);
526526
os::change_dir(path);
527-
let contents = os::list_dir(".");
527+
let contents = os::list_dir_path(".");
528528

529529
#debug("contents: %s", str::connect(contents, ", "));
530530

src/compiletest/compiletest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn test_opts(config: config) -> test::test_opts {
127127
fn make_tests(config: config) -> [test::test_desc] {
128128
#debug("making tests from %s", config.src_base);
129129
let mut tests = [];
130-
for file: str in os::list_dir(config.src_base) {
130+
for file: str in os::list_dir_path(config.src_base) {
131131
let file = file;
132132
#debug("inspecting file %s", file);
133133
if is_test(config, file) {

src/fuzzer/fuzzer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn find_rust_files(&files: [str], path: str) {
2525
} else if os::path_is_dir(path)
2626
&& !contains(path, "compile-fail")
2727
&& !contains(path, "build") {
28-
for p in os::list_dir(path) {
28+
for p in os::list_dir_path(path) {
2929
find_rust_files(files, p);
3030
}
3131
}

src/libcore/os.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export close, fclose, fsync_fd, waitpid;
2929
export env, getenv, setenv, fdopen, pipe;
3030
export getcwd, dll_filename, self_exe_path;
3131
export exe_suffix, dll_suffix, sysname;
32-
export homedir, list_dir, path_is_dir, path_exists, make_absolute,
33-
make_dir, remove_dir, change_dir, remove_file;
32+
export homedir, list_dir, list_dir_path, path_is_dir, path_exists,
33+
make_absolute, make_dir, remove_dir, change_dir, remove_file;
3434

3535
// FIXME: move these to str perhaps?
3636
export as_c_charp, fill_charp_buf;
@@ -452,26 +452,37 @@ fn list_dir(p: path) -> [str] {
452452
#[cfg(target_os = "linux")]
453453
#[cfg(target_os = "macos")]
454454
#[cfg(target_os = "freebsd")]
455-
fn star() -> str { "" }
455+
fn star(p: str) -> str { p }
456456

457457
#[cfg(target_os = "win32")]
458-
fn star() -> str { "*" }
458+
fn star(p: str) -> str {
459+
let pl = str::len(p);
460+
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
461+
** p[pl - 1u] as char != path::consts::alt_path_sep) {
462+
p + path::path_sep() + "*"
463+
} else {
464+
p + "*"
465+
}
466+
}
459467

468+
rustrt::rust_list_files(star(p)).filter {|filename|
469+
!str::eq(filename, ".") || !str::eq(filename, "..")
470+
}
471+
}
472+
473+
#[doc = "
474+
Lists the contents of a directory
475+
476+
This version prepends each entry with the directory.
477+
"]
478+
fn list_dir_path(p: path) -> [str] {
460479
let mut p = p;
461480
let pl = str::len(p);
462481
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
463482
&& p[pl - 1u] as char != path::consts::alt_path_sep) {
464483
p += path::path_sep();
465484
}
466-
let mut full_paths: [str] = [];
467-
for vec::each(rustrt::rust_list_files(p + star())) {|filename|
468-
if !str::eq(filename, ".") {
469-
if !str::eq(filename, "..") {
470-
full_paths += [p + filename];
471-
}
472-
}
473-
}
474-
ret full_paths;
485+
os::list_dir(p).map {|f| p + f}
475486
}
476487

477488
#[doc = "Removes a directory at the specified path"]
@@ -750,4 +761,4 @@ mod tests {
750761
assert (!os::path_exists("test/nonexistent-bogus-path"));
751762
}
752763

753-
}
764+
}

src/rustc/util/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn mk_filesearch(maybe_sysroot: option<path>,
6969
fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> {
7070
for lib_search_path in filesearch.lib_search_paths() {
7171
#debug("searching %s", lib_search_path);
72-
for path in os::list_dir(lib_search_path) {
72+
for path in os::list_dir_path(lib_search_path) {
7373
#debug("testing %s", path);
7474
let maybe_picked = pick(path);
7575
if option::is_some(maybe_picked) {

0 commit comments

Comments
 (0)