Merge pull request #1318 from elly/cargo

std: file_is_dir -> path_is_dir, add path_exists
This commit is contained in:
Graydon Hoare 2011-12-16 14:43:55 -08:00
commit 8dc5c445cc
6 changed files with 39 additions and 13 deletions

View File

@ -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];
}

View File

@ -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) {

View File

@ -12,7 +12,8 @@
#[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 });
}
/*

View File

@ -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;}

View File

@ -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
rust_uv_size_of_idle_t

View File

@ -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 == "";
}
}