From 6ab9e2656b8aa3d43c4977cc09a098dec7bcdafd Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Sun, 2 Aug 2020 12:39:32 -0600
Subject: [PATCH] Redox Scheme Path Prefix

---
 src/libstd/path.rs          | 21 +++++++--------------
 src/libstd/sys/unix/path.rs |  9 ++++++++-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 392c815ef280..47f7c02539fb 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -184,6 +184,10 @@ pub enum Prefix<'a> {
     /// Prefix `C:` for the given disk drive.
     #[stable(feature = "rust1", since = "1.0.0")]
     Disk(#[stable(feature = "rust1", since = "1.0.0")] u8),
+
+    /// Scheme `file:` used on Redox
+    #[stable(feature = "rust1", since = "1.0.0")]
+    Scheme(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr),
 }
 
 impl<'a> Prefix<'a> {
@@ -202,7 +206,7 @@ fn os_str_len(s: &OsStr) -> usize {
             UNC(x, y) => 2 + os_str_len(x) + if os_str_len(y) > 0 { 1 + os_str_len(y) } else { 0 },
             DeviceNS(x) => 4 + os_str_len(x),
             Disk(_) => 2,
-        }
+            Scheme(x) => 1 + os_str_len(x),        }
     }
 
     /// Determines if the prefix is verbatim, i.e., begins with `\\?\`.
@@ -304,11 +308,6 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
     &*(s as *const [u8] as *const OsStr)
 }
 
-// Detect scheme on Redox
-fn has_redox_scheme(s: &[u8]) -> bool {
-    cfg!(target_os = "redox") && s.contains(&b':')
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // Cross-platform, iterator-independent parsing
 ////////////////////////////////////////////////////////////////////////////////
@@ -1892,12 +1891,7 @@ pub fn to_path_buf(&self) -> PathBuf {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[allow(deprecated)]
     pub fn is_absolute(&self) -> bool {
-        if cfg!(target_os = "redox") {
-            // FIXME: Allow Redox prefixes
-            self.has_root() || has_redox_scheme(self.as_u8_slice())
-        } else {
-            self.has_root() && (cfg!(unix) || self.prefix().is_some())
-        }
+        self.has_root() && (cfg!(unix) || self.prefix().is_some())
     }
 
     /// Returns `true` if the `Path` is relative, i.e., not absolute.
@@ -2299,8 +2293,7 @@ pub fn components(&self) -> Components<'_> {
         Components {
             path: self.as_u8_slice(),
             prefix,
-            has_physical_root: has_physical_root(self.as_u8_slice(), prefix)
-                || has_redox_scheme(self.as_u8_slice()),
+            has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
             front: State::Prefix,
             back: State::Body,
         }
diff --git a/src/libstd/sys/unix/path.rs b/src/libstd/sys/unix/path.rs
index 840a7ae04262..1b6412245c65 100644
--- a/src/libstd/sys/unix/path.rs
+++ b/src/libstd/sys/unix/path.rs
@@ -11,7 +11,14 @@ pub fn is_verbatim_sep(b: u8) -> bool {
     b == b'/'
 }
 
-pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
+pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
+    if cfg!(target_os = "redox") {
+        if let Some(path_str) = path.to_str() {
+            if let Some(i) = path_str.find(':') {
+                return Some(Prefix::Scheme(OsStr::new(&path_str[..i])));
+            }
+        }
+    }
     None
 }
 
-- 
GitLab