Skip to content

Commit 18bf054

Browse files
committed
Fix redox prefix handling
1 parent a0b5dfe commit 18bf054

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/libstd/path.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ use sys::path::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix};
129129
// Windows Prefixes
130130
////////////////////////////////////////////////////////////////////////////////
131131

132-
/// Path prefixes (Windows only).
132+
/// Path prefixes (Redox and Windows only).
133+
///
134+
/// Redox uses schemes like `scheme:reference` to identify different I/O systems
133135
///
134136
/// Windows uses a variety of path styles, including references to drive
135137
/// volumes (like `C:`), network shared folders (like `\\server\share`) and
@@ -139,6 +141,10 @@ use sys::path::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix};
139141
#[derive(Copy, Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
140142
#[stable(feature = "rust1", since = "1.0.0")]
141143
pub enum Prefix<'a> {
144+
/// Prefix `scheme:`, where `scheme` is the component stored
145+
#[unstable(feature="redox_prefix", issue="0")]
146+
Scheme(&'a OsStr),
147+
142148
/// Prefix `\\?\`, together with the given component immediately following it.
143149
#[stable(feature = "rust1", since = "1.0.0")]
144150
Verbatim(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr),
@@ -178,6 +184,7 @@ impl<'a> Prefix<'a> {
178184
os_str_as_u8_slice(s).len()
179185
}
180186
match *self {
187+
Scheme(x) => os_str_len(x) + 1,
181188
Verbatim(x) => 4 + os_str_len(x),
182189
VerbatimUNC(x, y) => {
183190
8 + os_str_len(x) +

src/libstd/sys/redox/path.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ pub fn is_verbatim_sep(b: u8) -> bool {
2121
b == b'/'
2222
}
2323

24-
pub fn parse_prefix(_: &OsStr) -> Option<Prefix> {
25-
None
24+
pub fn parse_prefix(path: &OsStr) -> Option<Prefix> {
25+
if let Some(path_str) = path.to_str() {
26+
if let Some(i) = path_str.find(':') {
27+
Some(Prefix::Scheme(OsStr::new(&path_str[..i])))
28+
} else {
29+
None
30+
}
31+
} else {
32+
None
33+
}
2634
}
2735

2836
pub const MAIN_SEP_STR: &'static str = "/";

0 commit comments

Comments
 (0)