Skip to content

Commit 4d2c764

Browse files
committed
---
yaml --- r: 5698 b: refs/heads/master c: 82ef851 h: refs/heads/master v: v3
1 parent c381d53 commit 4d2c764

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
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: 8b4601e08eb0ac54f4c8c12b4dd762b89248abca
2+
refs/heads/master: 82ef8519c3ce9c2bf1176a6319cccbb3a5376bd2

trunk/src/lib/fs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ fn normalize(p: path) -> path {
144144
ret t;
145145
}
146146

147+
#[cfg(target_os = "linux")]
148+
#[cfg(target_os = "macos")]
147149
fn reabsolute(orig: path, new: path) -> path {
148150
if path_is_absolute(orig) {
149151
path_sep() + new
@@ -152,6 +154,15 @@ fn normalize(p: path) -> path {
152154
}
153155
}
154156

157+
#[cfg(target_os = "win32")]
158+
fn reabsolute(orig: path, new: path) -> path {
159+
if path_is_absolute(orig) && orig[0] == os_fs::path_sep as u8 {
160+
str::from_char(os_fs::path_sep) + new
161+
} else {
162+
new
163+
}
164+
}
165+
155166
fn reterminate(orig: path, new: path) -> path {
156167
let last = orig[str::byte_len(orig) - 1u];
157168
if last == os_fs::path_sep as u8

trunk/src/lib/win32_fs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ fn list_dir(path: str) -> [str] {
1212

1313
fn path_is_absolute(p: str) -> bool {
1414
ret str::char_at(p, 0u) == '/' ||
15-
str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\';
15+
str::char_at(p, 1u) == ':'
16+
&& (str::char_at(p, 2u) == path_sep
17+
|| str::char_at(p, 2u) == alt_path_sep);
1618
}
1719

1820
/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly

trunk/src/test/stdtest/fs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ fn normalize9() {
132132
fn normalize10() {
133133
let actual = fs::normalize("/a/b/c/../d/./../../e/");
134134
let expected = "/a/e/";
135+
log_err actual;
135136
assert actual == expected;
136137
}
137138

@@ -140,4 +141,19 @@ fn normalize11() {
140141
let actual = fs::normalize("/a/..");
141142
let expected = "/";
142143
assert actual == expected;
144+
}
145+
146+
#[test]
147+
#[cfg(target_os = "win32")]
148+
fn normalize12() {
149+
let actual = fs::normalize("C:/whatever");
150+
let expected = "C:/whatever";
151+
log_err actual;
152+
assert actual == expected;
153+
}
154+
155+
#[test]
156+
#[cfg(target_os = "win32")]
157+
fn path_is_absolute_win32() {
158+
assert fs::path_is_absolute("C:/whatever");
143159
}

0 commit comments

Comments
 (0)