about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorElly Jones <elly@leptoquark.net>2011-12-16 17:32:09 -0500
committerElly Jones <elly@leptoquark.net>2011-12-16 17:37:21 -0500
commit89e880d613bc797b3867f91cd7f676c9b4737397 (patch)
tree1bdaa03dc685a13b84ff2954767f771e86bb8f21 /src
parentb11268780ed7961c710d6a66665b82a2e5019a08 (diff)
downloadrust-89e880d613bc797b3867f91cd7f676c9b4737397.tar.gz
rust-89e880d613bc797b3867f91cd7f676c9b4737397.zip
std: file_is_dir -> path_is_dir, add path_exists
Diffstat (limited to 'src')
-rw-r--r--src/cargo/cargo.rs2
-rw-r--r--src/fuzzer/fuzzer.rs2
-rw-r--r--src/libstd/fs.rs18
-rw-r--r--src/rt/rust_builtin.cpp11
-rw-r--r--src/rt/rustrt.def.in5
-rw-r--r--src/test/stdtest/fs.rs14
6 files changed, 39 insertions, 13 deletions
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
+}