-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Deprecate std::path::Path's aliases of std::fs
functions.
#80741
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
Deprecate std::path::Path's aliases of std::fs
functions.
#80741
Conversation
`std::path::Path` has several functions which are trivial aliases for `std::fs` functions (eg. [`metadata`]) and a few which are minor convenience wrappers for `std::fs` functions (eg. [`is_file`]). [`metadata`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.metadata [`is_file`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file This PR deprecates these functions, so that `std` only has one preferred name for these operations. And it clarifies the role of the `std::path` module, which otherwise just has pure data structures and algorithms. The convenience wrappers, `is_file`, `is_dir`, and `exists`, are operations for which seemingly obvious uses are prone to TOCTTOU errors. So while it would be straightforward to add corresponding similar convenience functions to `std::fs`, this PR does not propose doing so. Specifically, this PR deprecates the 5 functions in `std::path::Path` which are trivial aliases of functions in `std::fs`: - [`metadata`](https://doc.rust-lang.org/std/path/struct.Path.html#method.metadata) - [`symlink_metadata`](https://doc.rust-lang.org/std/path/struct.Path.html#method.symlink_metadata) - [`canonicalize`](https://doc.rust-lang.org/std/path/struct.Path.html#method.canonicalize) - [`read_link`](https://doc.rust-lang.org/std/path/struct.Path.html#method.read_link) - [`read_dir`](https://doc.rust-lang.org/std/path/struct.Path.html#method.read_dir) and the 3 which are convenience wrappers around `std::fs::metadata`: - [`is_file`](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file) - [`is_dir`](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_dir) - [`exists`](https://doc.rust-lang.org/std/path/struct.Path.html#method.exists)
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This also eliminates one of the two path lookups on the input.
This comment has been minimized.
This comment has been minimized.
/// | ||
/// When the goal is simply to read from the source, the most reliable way to | ||
/// test the source can be read is to open it. See [`fs::read_dir`] for more | ||
/// information. |
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.
I don't think we need to update the deprecated docs.
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.
I added this because is_file
already has a similar comment, and these comments relate to one of the reasons for deprecating these functions, so it seems like useful context.
I would find the helper function still useful when we only have |
This comment has been minimized.
This comment has been minimized.
5744648
to
cc65c85
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Doesn't deprecating those methods cause too much churns represented by now? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4065cd5
to
4ee86d2
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
Co-authored-by: Ivan Tham <[email protected]>
4ee86d2
to
b7aae1b
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
I don't have a strong opinion about the convenience functions, and it turns out they're used a lot in Rust's own codebase, so I've now added new convenience functions This PR is a work in progress at this point; there's more code in Rust that needs to be updated to avoid the new deprecation warnings, since these warnings are interpreted as errors in the Rust build. |
This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
…ion. This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
…l, r=davidtwco Optimize away a `fs::metadata` call. This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
…ental, r=nagisa Optimize away some `fs::metadata` calls. This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
☔ The latest upstream changes (presumably #80756) made this pull request unmergeable. Please resolve the merge conflicts. |
From here and the internals thread it sounds like there isn't a lot of enthusiasm for these changes, so I'll close this. |
Optimize away some path lookups in the generic `fs::copy` implementation This also eliminates a use of a `Path` convenience function, in support of rust-lang#80741, refactoring `std::path` to focus on pure data structures and algorithms.
std::path::Path
has several functions which are trivial aliases forstd::fs
functions (eg.
metadata
) and a few which are minor convenience wrappers forstd::fs
functions (eg.is_file
).This PR deprecates these functions, so that
std
only has one preferred namefor these operations. And it clarifies the role of the
std::path
module, whichotherwise just has pure data structures and algorithms.
The convenience wrappers,is_file
,is_dir
, andexists
, are operations forwhich seemingly obvious uses are prone to TOCTTOU errors. So while it would be
straightforward to add corresponding similar convenience functions to
std::fs
,this PR does not propose doing so.
This PR also adds convenience functions
exists
,is_file
,is_dir
, tostd::fs
,in a dedicated commit.
Specifically, this PR deprecates the 5 functions in
std::path::Path
which aretrivial aliases of functions in
std::fs
:metadata
symlink_metadata
canonicalize
read_link
read_dir
and the 3 which are convenience wrappers around
std::fs::metadata
:is_file
is_dir
exists