]> git.lizzy.rs Git - rust.git/commitdiff
redox: Require scheme for path to be absolute
authorIan Douglas Scott <ian@iandouglasscott.com>
Fri, 18 Aug 2017 19:04:45 +0000 (12:04 -0700)
committerIan Douglas Scott <ian@iandouglasscott.com>
Fri, 18 Aug 2017 19:04:45 +0000 (12:04 -0700)
Redox paths are problematic. It would make sense to add a `Scheme`
variant to the `std::path::Component` enum; but that would presumably be
a breaking change due to exhaustive matching. Alternately it could use
the existing `Prefix` variant, like Windows, but none of the existing
types of prefix make sense, Redox only has one kind, and adding a new
variant to that enum has the same issue as `Component`.

src/libstd/path.rs

index 4496de09b259097a9b15b72cdb97e20dbeed9cee..866b65ac7e4c33226718a748f5c2299c4465d01c 100644 (file)
@@ -1685,8 +1685,16 @@ pub fn to_path_buf(&self) -> PathBuf {
     #[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())
+        #[cfg(not(target_os = "redox"))]
+        {
+            self.has_root() && (cfg!(unix) || self.prefix().is_some())
+        }
+        #[cfg(target_os = "redox")]
+        {
+            // FIXME: Allow Redox prefixes
+            use os::unix::ffi::OsStrExt;
+            self.as_os_str().as_bytes().split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
+        }
     }
 
     /// Returns `true` if the `Path` is relative, i.e. not absolute.