Skip to content

Redox Scheme Path Prefix #51537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this variant is a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, how should this be addressed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The docs around Prefix imply that it's meant to be Windows-exclusive, so perhaps defining another type is the way to go? However, the only place where Prefix seems to be used is as part of Component, which is also a fully public enum and can't be extended with another kind of prefix.

It doesn't look like this part of the standard library was designed with this kind of extensibility in mind. Maybe in the next epoch the definition of Prefix could be changed (not sure if epochs allow these kinds of changes)?

Alternatively, you could define a std::os::redox::path::PathExt trait that's implemented by Path and allows access to the prefix. However, this does not allow Path::components to work like it should...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if epochs allow these kinds of changes

I've also thought of that, but I don't think it would work (though I'd love to be corrected!). How would that work? I guess you would somehow change the version of the Components enum and components() function being used depending on the epoch. But what if code using it then tried to pass the Components to code in the older epoch? Though perhaps an unlikely use case for this particular struct, that probably shouldn't error complaining that the types are different, and couldn't work because the code it's passed to won't know how to deal with the new variant.

}

impl<'a> Prefix<'a> {
Expand Down Expand Up @@ -221,6 +225,7 @@ impl<'a> Prefix<'a> {
},
DeviceNS(x) => 4 + os_str_len(x),
Disk(_) => 2,
Scheme(x) => 1 + os_str_len(x),
}

}
Expand Down Expand Up @@ -322,11 +327,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.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
}

////////////////////////////////////////////////////////////////////////////////
// Cross-platform, iterator-independent parsing
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1793,12 +1793,7 @@ impl Path {
#[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.
Expand Down Expand Up @@ -2201,8 +2196,7 @@ impl Path {
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,
}
Expand Down
5 changes: 2 additions & 3 deletions src/libstd/sys/redox/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ pub fn is_verbatim_sep(b: u8) -> bool {

pub fn parse_prefix(path: &OsStr) -> Option<Prefix> {
if let Some(path_str) = path.to_str() {
if let Some(_i) = path_str.find(':') {
if let Some(i) = path_str.find(':') {
// FIXME: Redox specific prefix
// Some(Prefix::Verbatim(OsStr::new(&path_str[..i])))
None
Some(Prefix::Scheme(OsStr::new(&path_str[..i])))
} else {
None
}
Expand Down