Skip to content

Commit b5a3483

Browse files
author
Elly Jones
committed
---
yaml --- r: 6759 b: refs/heads/master c: 89e880d h: refs/heads/master i: 6757: 079c433 6755: 03676b7 6751: 271d840 v: v3
1 parent 1ccdfe3 commit b5a3483

File tree

7 files changed

+40
-14
lines changed

7 files changed

+40
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b11268780ed7961c710d6a66665b82a2e5019a08
2+
refs/heads/master: 89e880d613bc797b3867f91cd7f676c9b4737397

trunk/src/cargo/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn rest(s: str, start: uint) -> str {
112112
}
113113

114114
fn need_dir(s: str) {
115-
if fs::file_is_dir(s) { ret; }
115+
if fs::path_is_dir(s) { ret; }
116116
if !fs::make_dir(s, 0x1c0i32) {
117117
fail #fmt["can't make_dir %s", s];
118118
}

trunk/src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn contains(haystack: str, needle: str) -> bool {
2323
fn find_rust_files(&files: [str], path: str) {
2424
if str::ends_with(path, ".rs") {
2525
files += [path];
26-
} else if fs::file_is_dir(path)
26+
} else if fs::path_is_dir(path)
2727
&& !contains(path, "compile-fail")
2828
&& !contains(path, "build") {
2929
for p in fs::list_dir(path) {

trunk/src/libstd/fs.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import os_fs;
1212

1313
#[abi = "cdecl"]
1414
native mod rustrt {
15-
fn rust_file_is_dir(path: str::sbuf) -> int;
15+
fn rust_path_is_dir(path: str::sbuf) -> int;
16+
fn rust_path_exists(path: str::sbuf) -> int;
1617
}
1718

1819
/*
@@ -110,12 +111,21 @@ fn connect_many(paths: [path]) : vec::is_not_empty(paths) -> path {
110111
}
111112

112113
/*
113-
Function: file_id_dir
114+
Function: path_is_dir
114115
115116
Indicates whether a path represents a directory.
116117
*/
117-
fn file_is_dir(p: path) -> bool {
118-
ret str::as_buf(p, {|buf| rustrt::rust_file_is_dir(buf) != 0 });
118+
fn path_is_dir(p: path) -> bool {
119+
ret str::as_buf(p, {|buf| rustrt::rust_path_is_dir(buf) != 0 });
120+
}
121+
122+
/*
123+
Function: path_exists
124+
125+
Indicates whether a path exists.
126+
*/
127+
fn path_exists(p: path) -> bool {
128+
ret str::as_buf(p, {|buf| rustrt::rust_path_exists(buf) != 0 });
119129
}
120130

121131
/*

trunk/src/rt/rust_builtin.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,23 @@ rust_list_files(rust_str *path) {
319319
}
320320

321321
extern "C" CDECL int
322-
rust_file_is_dir(char *path) {
322+
rust_path_is_dir(char *path) {
323323
struct stat buf;
324324
if (stat(path, &buf)) {
325325
return 0;
326326
}
327327
return S_ISDIR(buf.st_mode);
328328
}
329329

330+
extern "C" CDECL int
331+
rust_path_exists(char *path) {
332+
struct stat buf;
333+
if (stat(path, &buf)) {
334+
return 0;
335+
}
336+
return 1;
337+
}
338+
330339
extern "C" CDECL FILE* rust_get_stdin() {return stdin;}
331340
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
332341
extern "C" CDECL FILE* rust_get_stderr() {return stderr;}

trunk/src/rt/rustrt.def.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ rand_free
2828
rand_new
2929
rand_next
3030
refcount
31-
rust_file_is_dir
31+
rust_path_is_dir
32+
rust_path_exists
3233
rust_getcwd
3334
rust_get_stdin
3435
rust_get_stdout
@@ -80,4 +81,4 @@ rust_uv_run
8081
rust_uv_unref
8182
rust_uv_idle_init
8283
rust_uv_idle_start
83-
rust_uv_size_of_idle_t
84+
rust_uv_size_of_idle_t

trunk/src/test/stdtest/fs.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ fn list_dir() {
2626
}
2727

2828
#[test]
29-
fn file_is_dir() {
30-
assert (fs::file_is_dir("."));
31-
assert (!fs::file_is_dir("test/stdtest/fs.rs"));
29+
fn path_is_dir() {
30+
assert (fs::path_is_dir("."));
31+
assert (!fs::path_is_dir("test/stdtest/fs.rs"));
32+
}
33+
34+
#[test]
35+
fn path_exists() {
36+
assert (fs::path_exists("."));
37+
assert (!fs::path_exists("test/nonexistent-bogus-path"));
3238
}
3339

3440
fn ps() -> str {
@@ -214,4 +220,4 @@ fn splitext_nobasename() {
214220
let (base, ext) = fs::splitext("oh.my/");
215221
assert base == "oh.my/";
216222
assert ext == "";
217-
}
223+
}

0 commit comments

Comments
 (0)