Skip to content

Conversation

@Ayush1325
Copy link
Contributor

@Ayush1325 Ayush1325 commented Jan 12, 2025

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.

@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 12, 2025
@tgross35
Copy link
Contributor

tgross35 commented Jan 13, 2025

This winds up keeping roughly the same pattern but has it repeated it in a few places, I'm not sure how strong the benefit is here. The UEFI implementation does look more complex though - would it work to leave the existing code but do something like this?

#[cfg(not(target_os = "uefi")]
return sys::path::is_absolute(self);

if cfg!(target_os = "redox") { /* rest of the existing code */ }

@Ayush1325
Copy link
Contributor Author

This winds up keeping roughly the same pattern but has it repeated it in a few places, I'm not sure how strong the benefit is here. The UEFI implementation does look more complex though - would it work to leave the existing code but do something like this?

#[cfg(not(target_os = "uefi")]
return sys::path::is_absolute(self);

if cfg!(target_os = "redox") { /* rest of the existing code */ }

Well, the UEFI absolute check is pretty simple as well:

cfg!(target_os = "uefi") && (path.as_os_str().as_encoded_bytes().contains(&COLON) || path.as_os_str().as_encoded_bytes().contains(&FORWARD_SLASH))

With that said, I thought it was the policy not to introduce any new platform-specific behaviour outside of sys.

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]: rust-lang#135368
[1]: rust-lang#52331 (comment)

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
@tgross35
Copy link
Contributor

Well, the UEFI absolute check is pretty simple as well:

Ah thanks, I was looking at the wrong code.

With that said, I thought it was the policy not to introduce any new platform-specific behaviour outside of sys.

I wouldn't think there could be much wrong with adding another branch to the existing config, especially considering that exact if block more or less has to exist in Unix anyway. That being said, this change is fine and may make things cleaner in the future with more targets. One small request then lgtm.

@tgross35
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 13, 2025

📌 Commit 1107382 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 13, 2025
@bors bors merged commit b8dab0e into rust-lang:master Jan 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 14, 2025
@Ayush1325 Ayush1325 deleted the path-is-absolute branch January 14, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants