path: Move is_absolute check to sys::path
I am working on fs support for UEFI [0], which similar to windows has prefix components, but is not quite same as Windows. It also seems that Prefix is tied closely to Windows and cannot really be extended [1]. This PR just tries to remove coupling between Prefix and absolute path checking to allow platforms to provide there own implementation to check if a path is absolute or not. I am not sure if any platform other than windows currently uses Prefix, so I have kept the path.prefix().is_some() check in most cases. [0]: https://github.com/rust-lang/rust/pull/135368 [1]: https://github.com/rust-lang/rust/issues/52331#issuecomment-2492796137 Signed-off-by: Ayush Singh <ayush@beagleboard.org>
This commit is contained in:
parent
12445e0b2c
commit
1107382a18
5 changed files with 27 additions and 11 deletions
|
@ -298,7 +298,7 @@ where
|
|||
}
|
||||
|
||||
// Detect scheme on Redox
|
||||
fn has_redox_scheme(s: &[u8]) -> bool {
|
||||
pub(crate) fn has_redox_scheme(s: &[u8]) -> bool {
|
||||
cfg!(target_os = "redox") && s.contains(&b':')
|
||||
}
|
||||
|
||||
|
@ -2155,7 +2155,7 @@ impl Path {
|
|||
unsafe { Path::new(OsStr::from_encoded_bytes_unchecked(s)) }
|
||||
}
|
||||
// The following (private!) function reveals the byte encoding used for OsStr.
|
||||
fn as_u8_slice(&self) -> &[u8] {
|
||||
pub(crate) fn as_u8_slice(&self) -> &[u8] {
|
||||
self.inner.as_encoded_bytes()
|
||||
}
|
||||
|
||||
|
@ -2323,14 +2323,7 @@ impl Path {
|
|||
#[must_use]
|
||||
#[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!(any(unix, target_os = "hermit", target_os = "wasi"))
|
||||
|| self.prefix().is_some())
|
||||
}
|
||||
sys::path::is_absolute(self)
|
||||
}
|
||||
|
||||
/// Returns `true` if the `Path` is relative, i.e., not absolute.
|
||||
|
@ -2353,7 +2346,7 @@ impl Path {
|
|||
!self.is_absolute()
|
||||
}
|
||||
|
||||
fn prefix(&self) -> Option<Prefix<'_>> {
|
||||
pub(crate) fn prefix(&self) -> Option<Prefix<'_>> {
|
||||
self.components().prefix
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue