mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 03:25:55 +00:00
Fix some path handling in std::fs on win32
This commit is contained in:
parent
8b4601e08e
commit
82ef8519c3
@ -144,6 +144,8 @@ fn normalize(p: path) -> path {
|
||||
ret t;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn reabsolute(orig: path, new: path) -> path {
|
||||
if path_is_absolute(orig) {
|
||||
path_sep() + new
|
||||
@ -152,6 +154,15 @@ fn normalize(p: path) -> path {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
fn reabsolute(orig: path, new: path) -> path {
|
||||
if path_is_absolute(orig) && orig[0] == os_fs::path_sep as u8 {
|
||||
str::from_char(os_fs::path_sep) + new
|
||||
} else {
|
||||
new
|
||||
}
|
||||
}
|
||||
|
||||
fn reterminate(orig: path, new: path) -> path {
|
||||
let last = orig[str::byte_len(orig) - 1u];
|
||||
if last == os_fs::path_sep as u8
|
||||
|
@ -12,7 +12,9 @@ fn list_dir(path: str) -> [str] {
|
||||
|
||||
fn path_is_absolute(p: str) -> bool {
|
||||
ret str::char_at(p, 0u) == '/' ||
|
||||
str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\';
|
||||
str::char_at(p, 1u) == ':'
|
||||
&& (str::char_at(p, 2u) == path_sep
|
||||
|| str::char_at(p, 2u) == alt_path_sep);
|
||||
}
|
||||
|
||||
/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly
|
||||
|
@ -132,6 +132,7 @@ fn normalize9() {
|
||||
fn normalize10() {
|
||||
let actual = fs::normalize("/a/b/c/../d/./../../e/");
|
||||
let expected = "/a/e/";
|
||||
log_err actual;
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
@ -140,4 +141,19 @@ fn normalize11() {
|
||||
let actual = fs::normalize("/a/..");
|
||||
let expected = "/";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "win32")]
|
||||
fn normalize12() {
|
||||
let actual = fs::normalize("C:/whatever");
|
||||
let expected = "C:/whatever";
|
||||
log_err actual;
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "win32")]
|
||||
fn path_is_absolute_win32() {
|
||||
assert fs::path_is_absolute("C:/whatever");
|
||||
}
|
Loading…
Reference in New Issue
Block a user