diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 3347b367ee2..d698011f298 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -112,7 +112,7 @@ fn rest(s: str, start: uint) -> str { } fn need_dir(s: str) { - if fs::file_is_dir(s) { ret; } + if fs::path_is_dir(s) { ret; } if !fs::make_dir(s, 0x1c0i32) { fail #fmt["can't make_dir %s", s]; } diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 983d2b5e9f3..76e5b8d18f9 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -23,7 +23,7 @@ fn contains(haystack: str, needle: str) -> bool { fn find_rust_files(&files: [str], path: str) { if str::ends_with(path, ".rs") { files += [path]; - } else if fs::file_is_dir(path) + } else if fs::path_is_dir(path) && !contains(path, "compile-fail") && !contains(path, "build") { for p in fs::list_dir(path) { diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index eac2347748e..46dad7b2bbb 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -12,7 +12,8 @@ import os_fs; #[abi = "cdecl"] native mod rustrt { - fn rust_file_is_dir(path: str::sbuf) -> int; + fn rust_path_is_dir(path: str::sbuf) -> int; + fn rust_path_exists(path: str::sbuf) -> int; } /* @@ -110,12 +111,21 @@ fn connect_many(paths: [path]) : vec::is_not_empty(paths) -> path { } /* -Function: file_id_dir +Function: path_is_dir Indicates whether a path represents a directory. */ -fn file_is_dir(p: path) -> bool { - ret str::as_buf(p, {|buf| rustrt::rust_file_is_dir(buf) != 0 }); +fn path_is_dir(p: path) -> bool { + ret str::as_buf(p, {|buf| rustrt::rust_path_is_dir(buf) != 0 }); +} + +/* +Function: path_exists + +Indicates whether a path exists. +*/ +fn path_exists(p: path) -> bool { + ret str::as_buf(p, {|buf| rustrt::rust_path_exists(buf) != 0 }); } /* diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index dd5831c2917..28c819879b6 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -319,7 +319,7 @@ rust_list_files(rust_str *path) { } extern "C" CDECL int -rust_file_is_dir(char *path) { +rust_path_is_dir(char *path) { struct stat buf; if (stat(path, &buf)) { return 0; @@ -327,6 +327,15 @@ rust_file_is_dir(char *path) { return S_ISDIR(buf.st_mode); } +extern "C" CDECL int +rust_path_exists(char *path) { + struct stat buf; + if (stat(path, &buf)) { + return 0; + } + return 1; +} + extern "C" CDECL FILE* rust_get_stdin() {return stdin;} extern "C" CDECL FILE* rust_get_stdout() {return stdout;} extern "C" CDECL FILE* rust_get_stderr() {return stderr;} diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index c1365f1685d..ff16cde5b18 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -28,7 +28,8 @@ rand_free rand_new rand_next refcount -rust_file_is_dir +rust_path_is_dir +rust_path_exists rust_getcwd rust_get_stdin rust_get_stdout @@ -80,4 +81,4 @@ rust_uv_run rust_uv_unref rust_uv_idle_init rust_uv_idle_start -rust_uv_size_of_idle_t \ No newline at end of file +rust_uv_size_of_idle_t diff --git a/src/test/stdtest/fs.rs b/src/test/stdtest/fs.rs index a57cebc332d..a9b1f5ea259 100644 --- a/src/test/stdtest/fs.rs +++ b/src/test/stdtest/fs.rs @@ -26,9 +26,15 @@ fn list_dir() { } #[test] -fn file_is_dir() { - assert (fs::file_is_dir(".")); - assert (!fs::file_is_dir("test/stdtest/fs.rs")); +fn path_is_dir() { + assert (fs::path_is_dir(".")); + assert (!fs::path_is_dir("test/stdtest/fs.rs")); +} + +#[test] +fn path_exists() { + assert (fs::path_exists(".")); + assert (!fs::path_exists("test/nonexistent-bogus-path")); } fn ps() -> str { @@ -214,4 +220,4 @@ fn splitext_nobasename() { let (base, ext) = fs::splitext("oh.my/"); assert base == "oh.my/"; assert ext == ""; -} \ No newline at end of file +}