about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-08-23 08:44:25 -0400
committerGitHub <noreply@github.com>2017-08-23 08:44:25 -0400
commitdd58d4e45ee2f066711557cf2da53d8661a56f34 (patch)
treecf1e9306196417f950975f0c923d8000fd450791 /src/libstd/path.rs
parent4902e6714ff3b54b745631125b3c01bc01ae096d (diff)
parentfe2d661931852c4303b45bed472640bd0b32448f (diff)
downloadrust-dd58d4e45ee2f066711557cf2da53d8661a56f34.tar.gz
rust-dd58d4e45ee2f066711557cf2da53d8661a56f34.zip
Rollup merge of #43983 - ids1024:redox-path-prefix, r=alexcrichton
Redox: correct is_absolute() and has_root()

This is awkward, but representing schemes properly in `Components` is not easily possible without breaking backwards compatibility, as discussed earlier in https://github.com/rust-lang/rust/pull/37702.

But these methods can be corrected anyway.
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 680bb057858..830b9dc475d 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -323,6 +323,11 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
     mem::transmute(s)
 }
 
+// Detect scheme on Redox
+fn has_redox_scheme(s: &[u8]) -> bool {
+    cfg!(target_os = "redox") && s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Cross-platform, iterator-independent parsing
 ////////////////////////////////////////////////////////////////////////////////
@@ -1685,8 +1690,12 @@ impl Path {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[allow(deprecated)]
     pub fn is_absolute(&self) -> bool {
-        // FIXME: Remove target_os = "redox" and allow Redox prefixes
-        self.has_root() && (cfg!(unix) || cfg!(target_os = "redox") || self.prefix().is_some())
+        if !cfg!(target_os = "redox") {
+            self.has_root() && (cfg!(unix) || self.prefix().is_some())
+        } else {
+            // FIXME: Allow Redox prefixes
+            has_redox_scheme(self.as_u8_slice())
+        }
     }
 
     /// Returns `true` if the `Path` is relative, i.e. not absolute.
@@ -2050,7 +2059,8 @@ impl Path {
         Components {
             path: self.as_u8_slice(),
             prefix,
-            has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
+            has_physical_root: has_physical_root(self.as_u8_slice(), prefix) ||
+                               has_redox_scheme(self.as_u8_slice()),
             front: State::Prefix,
             back: State::Body,
         }