-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Added try_exists()
method to std::path::Path
#81822
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
94e5cc9
to
d9e4008
Compare
This comment has been minimized.
This comment has been minimized.
One thing I'm unclear on is how this should work on other platforms. I'm thinking in particular of Windows which does not have the same folder issue as Linux but has its own way of working. E.g.
If a file does exist but reading its metadata fails, then should it return an error? Or |
@ChrisDenton access denied is just one (obvious) example, there can be various other reasons depending on the underlying OS.
If |
d9e4008
to
f92d9df
Compare
Yes the behaviour can be very OS specific, which is the point I was trying to make using Windows as an example. But if the idea is to return |
This comment has been minimized.
This comment has been minimized.
f92d9df
to
5849ee2
Compare
This looks good to me (with the suggested fix applied). Thank you for working on this! |
This method is similar to the existing `exists()` method, except it doesn't silently ignore the errors, leading to less error-prone code. This change intentionally does NOT touch the documentation of `exists()` nor recommend people to use this method while it's unstable. Such changes are reserved for stabilization to prevent confusing people. Apart from that it avoids conflicts with rust-lang#80979.
9081cdd
to
66f7f7d
Compare
@joshtriplett I guess you meant fix that Should I open the tracking issue already or wait for something first? |
@ChrisDenton do I understand correctly that Windows has some other function to check if file exists and also a function to read metadata and the latter could fail even if the former doesn't? |
There are two issues I think. The first one is really about how The second issue is that I don't think we necessarily need to handle or document all possibilities but I think there could be some more robust wording about what an error can mean. Though I'm struggling with how to phrase it. |
@ChrisDenton thank you for explaining! I'd actually prefer to handle those cases properly. If the function name indicates checking of existence of a file it should be as close to reality as possible. It also avoids wordy documentation of such behavior. |
library/std/src/path.rs
Outdated
/// ``` | ||
// FIXME: stabilization should modify documentation of `exists()` to recommend this method | ||
// instead. | ||
#[unstable(feature = "path_try_exists", issue = "none")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rust-lang/libs if no one opposes i'll r+ after the tracking issue is filed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took it as "yes" answer to my question about opening the tracking issue, so I opened it (#83186) and filled.
This adds the ID of the tracking issue to the feature.
@bors r+ rollup |
📌 Commit 4330268 has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#81822 (Added `try_exists()` method to `std::path::Path`) - rust-lang#83072 (Update `Vec` docs) - rust-lang#83077 (rustdoc: reduce GC work during search) - rust-lang#83091 (Constify `copy` related functions) - rust-lang#83156 (Fall-back to sans-serif if Arial is not available) - rust-lang#83157 (No background for code in portability snippets) - rust-lang#83160 (Deprecate RustcEncodable and RustcDecodable.) - rust-lang#83162 (Specify *.woff2 files as binary) - rust-lang#83172 (More informative diagnotic from `x.py test` attempt atop beta checkout) - rust-lang#83196 (Use delay_span_bug instead of panic in layout_scalar_valid_range) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I want to use this for the same reason as rust-lang/rust#81822 was added to std. While it's currently unstable, I can't imagine it would change.
I want to use this for the same reason as rust-lang/rust#81822 was added to std. While it's currently unstable, I can't imagine it would change.
I want to use this for the same reason as rust-lang/rust#81822 was added to std. While it's currently unstable, I can't imagine it would change.
I want to use this for the same reason as rust-lang/rust#81822 was added to std. While it's currently unstable, I can't imagine it would change.
I want to use this for the same reason as rust-lang/rust#81822 was added to std. While it's currently unstable, I can't imagine it would change.
This method is similar to the existing
exists()
method, except itdoesn't silently ignore the errors, leading to less error-prone code.
This change intentionally does NOT touch the documentation of
exists()
nor recommend people to use this method while it's unstable.
Such changes are reserved for stabilization to prevent confusing people.
Apart from that it avoids conflicts with #80979.
@joshtriplett requested this PR in internals discussion