Skip to content

Commit e0f0fd0

Browse files
committed
Correct has_root() on Redox
1 parent b272f6c commit e0f0fd0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/libstd/path.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
323323
mem::transmute(s)
324324
}
325325

326+
// Detect scheme on Redox
327+
#[inline]
328+
#[allow(unused_variables)]
329+
fn has_scheme(s: &[u8]) -> bool {
330+
#[cfg(target_os = "redox")]
331+
{
332+
s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
333+
}
334+
#[cfg(not(target_os = "redox"))]
335+
{
336+
false
337+
}
338+
}
339+
326340
////////////////////////////////////////////////////////////////////////////////
327341
// Cross-platform, iterator-independent parsing
328342
////////////////////////////////////////////////////////////////////////////////
@@ -605,6 +619,9 @@ pub struct Components<'a> {
605619
// normalization, e.g. \\server\share == \\server\share\.
606620
has_physical_root: bool,
607621

622+
// For Redox
623+
has_scheme: bool,
624+
608625
// The iterator is double-ended, and these two states keep track of what has
609626
// been produced from either end
610627
front: State,
@@ -725,7 +742,7 @@ impl<'a> Components<'a> {
725742

726743
/// Is the *original* path rooted?
727744
fn has_root(&self) -> bool {
728-
if self.has_physical_root {
745+
if self.has_physical_root || self.has_scheme {
729746
return true;
730747
}
731748
if let Some(p) = self.prefix {
@@ -1692,8 +1709,7 @@ impl Path {
16921709
#[cfg(target_os = "redox")]
16931710
{
16941711
// FIXME: Allow Redox prefixes
1695-
use os::unix::ffi::OsStrExt;
1696-
self.as_os_str().as_bytes().split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
1712+
has_scheme(self.as_u8_slice())
16971713
}
16981714
}
16991715

@@ -2059,6 +2075,7 @@ impl Path {
20592075
path: self.as_u8_slice(),
20602076
prefix,
20612077
has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
2078+
has_scheme: has_scheme(self.as_u8_slice()),
20622079
front: State::Prefix,
20632080
back: State::Body,
20642081
}

0 commit comments

Comments
 (0)