std: file_is_dir -> path_is_dir, add path_exists
This commit is contained in:
parent
b11268780e
commit
89e880d613
@ -112,7 +112,7 @@ fn rest(s: str, start: uint) -> str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn need_dir(s: 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) {
|
if !fs::make_dir(s, 0x1c0i32) {
|
||||||
fail #fmt["can't make_dir %s", s];
|
fail #fmt["can't make_dir %s", s];
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ fn contains(haystack: str, needle: str) -> bool {
|
|||||||
fn find_rust_files(&files: [str], path: str) {
|
fn find_rust_files(&files: [str], path: str) {
|
||||||
if str::ends_with(path, ".rs") {
|
if str::ends_with(path, ".rs") {
|
||||||
files += [path];
|
files += [path];
|
||||||
} else if fs::file_is_dir(path)
|
} else if fs::path_is_dir(path)
|
||||||
&& !contains(path, "compile-fail")
|
&& !contains(path, "compile-fail")
|
||||||
&& !contains(path, "build") {
|
&& !contains(path, "build") {
|
||||||
for p in fs::list_dir(path) {
|
for p in fs::list_dir(path) {
|
||||||
|
@ -12,7 +12,8 @@ import os_fs;
|
|||||||
|
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
native mod rustrt {
|
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.
|
Indicates whether a path represents a directory.
|
||||||
*/
|
*/
|
||||||
fn file_is_dir(p: path) -> bool {
|
fn path_is_dir(p: path) -> bool {
|
||||||
ret str::as_buf(p, {|buf| rustrt::rust_file_is_dir(buf) != 0 });
|
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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -319,7 +319,7 @@ rust_list_files(rust_str *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL int
|
extern "C" CDECL int
|
||||||
rust_file_is_dir(char *path) {
|
rust_path_is_dir(char *path) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(path, &buf)) {
|
if (stat(path, &buf)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -327,6 +327,15 @@ rust_file_is_dir(char *path) {
|
|||||||
return S_ISDIR(buf.st_mode);
|
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_stdin() {return stdin;}
|
||||||
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
|
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
|
||||||
extern "C" CDECL FILE* rust_get_stderr() {return stderr;}
|
extern "C" CDECL FILE* rust_get_stderr() {return stderr;}
|
||||||
|
@ -28,7 +28,8 @@ rand_free
|
|||||||
rand_new
|
rand_new
|
||||||
rand_next
|
rand_next
|
||||||
refcount
|
refcount
|
||||||
rust_file_is_dir
|
rust_path_is_dir
|
||||||
|
rust_path_exists
|
||||||
rust_getcwd
|
rust_getcwd
|
||||||
rust_get_stdin
|
rust_get_stdin
|
||||||
rust_get_stdout
|
rust_get_stdout
|
||||||
@ -80,4 +81,4 @@ rust_uv_run
|
|||||||
rust_uv_unref
|
rust_uv_unref
|
||||||
rust_uv_idle_init
|
rust_uv_idle_init
|
||||||
rust_uv_idle_start
|
rust_uv_idle_start
|
||||||
rust_uv_size_of_idle_t
|
rust_uv_size_of_idle_t
|
||||||
|
@ -26,9 +26,15 @@ fn list_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn file_is_dir() {
|
fn path_is_dir() {
|
||||||
assert (fs::file_is_dir("."));
|
assert (fs::path_is_dir("."));
|
||||||
assert (!fs::file_is_dir("test/stdtest/fs.rs"));
|
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 {
|
fn ps() -> str {
|
||||||
@ -214,4 +220,4 @@ fn splitext_nobasename() {
|
|||||||
let (base, ext) = fs::splitext("oh.my/");
|
let (base, ext) = fs::splitext("oh.my/");
|
||||||
assert base == "oh.my/";
|
assert base == "oh.my/";
|
||||||
assert ext == "";
|
assert ext == "";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user