File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,8 @@ fn normalize(p: path) -> path {
144
144
ret t;
145
145
}
146
146
147
+ #[ cfg( target_os = "linux" ) ]
148
+ #[ cfg( target_os = "macos" ) ]
147
149
fn reabsolute ( orig : path , new : path ) -> path {
148
150
if path_is_absolute ( orig) {
149
151
path_sep ( ) + new
@@ -152,6 +154,15 @@ fn normalize(p: path) -> path {
152
154
}
153
155
}
154
156
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
+
155
166
fn reterminate ( orig : path , new : path ) -> path {
156
167
let last = orig[ str:: byte_len ( orig) - 1 u] ;
157
168
if last == os_fs:: path_sep as u8
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ fn list_dir(path: str) -> [str] {
12
12
13
13
fn path_is_absolute ( p : str ) -> bool {
14
14
ret str:: char_at ( p, 0 u) == '/' ||
15
- str:: char_at ( p, 1 u) == ':' && str:: char_at ( p, 2 u) == '\\' ;
15
+ str:: char_at ( p, 1 u) == ':'
16
+ && ( str:: char_at ( p, 2 u) == path_sep
17
+ || str:: char_at ( p, 2 u) == alt_path_sep) ;
16
18
}
17
19
18
20
/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly
Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ fn normalize9() {
132
132
fn normalize10 ( ) {
133
133
let actual = fs:: normalize ( "/a/b/c/../d/./../../e/" ) ;
134
134
let expected = "/a/e/" ;
135
+ log_err actual;
135
136
assert actual == expected;
136
137
}
137
138
@@ -140,4 +141,19 @@ fn normalize11() {
140
141
let actual = fs:: normalize ( "/a/.." ) ;
141
142
let expected = "/" ;
142
143
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" ) ;
143
159
}
You can’t perform that action at this time.
0 commit comments