-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for std::path::absolute
#92750
Comments
Ok, so cards on the table. My personal motivation for this function is to expose the Windows function GetFullPathNameW (or something similar) into the standard library in a way that can be used cross-platform. This is already used by the standard library for making verbatim paths (absolute paths that aren't limited by I'd like to address the unresolved issues of not resolving |
I feel this is mistaken. On Windows, when you pass a path to Here are some examples of the potential differences between using
The idea of |
Could you elaborate on that? I get that |
Yes. sorry I worded that badly. The |
Is there a particular reason this is added to the |
Mainly just to be more or less a drop-in replacement for |
The Resolving |
Thinking things over a bit I think we may want 2 functions.
|
What advantage would |
It would work on Windows in more scenarios and on paths which may partially exist or not exist at all. It can avoid filesystem access if there's no
You seem to suggest that end user programs should call different functions on Windows and Unix. That's not great for a portable API. |
The Libraries could build on this primitive to provide a number of other useful functions. They can't however unbuild it. If std only provides higher level functions, then it will not allow experimenting outside of std without those libraries having to reimplement it themselves. |
I agree this is useful. I want something close to this for implementing support for hyperlinks in ripgrep. Say, for example, a user is in But in order for |
The Unix case is tricky because there's no (safe) way to cleanup Can you say why |
Yeah, that's a good point. Apparently some stuff on Windows at least doesn't deal with |
@ChrisDenton Do you think this is ready for FCP? I think there are a couple things I'd like to see:
|
The first point is something I've been thinking about recently but it requires a bit of explanation to understand my thinking. Win32 has two legacy types of relative paths which are nonetheless still supported:
That second one is a pain point. It uses hidden state, which is fine when you're just asking the OS to figure out what the path really is but is very surprising when you asked it to join two paths together. Making it worse is that So I was thinking that something like the below would make sense, so it's clearer what you mean to happen: // This is just a sketch
pub fn absolute(base: Option<&Path>, path: &Path) -> io::Result<PathBuf> {
if let Some(base) = base {
if base.is_relative() || path.is_absolute() { return err }
// Note: `join_subpath` is a hypothetical function that, unlike `join`
// never overrides the base path
impl::absolute(base.join_subpath(path))
} else {
// If no base is given, just use `path`
impl::absolute(path)
}
}
If a user passes a path to a tool then they tend to expect printed paths to be in displayed in a similar manner to the way they were given. The canonicalized form may appear to be very different from the path the user typed. For Windows paths specifically, they're much easier for the programmer to handle in their normalized form, e.g. without legacy relative paths or other path based weirdness. But canonicalization can fail (e.g. if the path doesn't exist yet). |
Hmmm. Yeah that signature that takes a |
Yes, I'm fine with that if other people are. |
@rfcbot fcp merge
|
Team member @BurntSushi has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
What is "the root of the current directory"? Does this refer to the drive letter? |
Yes, for drive paths. It could also mean |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
…dtolnay Stabilize `std::path::absolute` FCP complete in rust-lang#92750 (comment)
…dtolnay Stabilize `std::path::absolute` FCP complete in rust-lang#92750 (comment)
…dtolnay Stabilize `std::path::absolute` FCP complete in rust-lang#92750 (comment)
Rollup merge of rust-lang#124335 - ChrisDenton:stabilize-absolute, r=dtolnay Stabilize `std::path::absolute` FCP complete in rust-lang#92750 (comment)
Stabilize `std::path::absolute` FCP complete in rust-lang/rust#92750 (comment)
Now that #124335 is merged, should this issue be closed? |
Feature gate:
#![feature(absolute_path)]
This is a tracking issue for
std::path::absolute
for making relative paths absolute without touching the filesystem. It is a drop-in replacement forstd::fs::canonicalize
.Public API
Steps / History
std::path::absolute
#91673Unresolved Questions
GetFullPathNameW
, which isn't quite a "pure" function (in some special cases, e.g.D:file.txt
, it can use hidden environment variables, set by cmd.exe, to resolve the path's root).absolute(a.join(b))
, wherea
is an alternative current directory to usingstd::env::current_dir
?..
actually the right call? It does seem consistent with the POSIX docs, but may not be the most intuitive behavior (particularly given that Windows doesn't do that).The text was updated successfully, but these errors were encountered: