rust-lang / rust-lang/rust-clippy
File path comparison without canonicalizing
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
When comparing paths, std does this purely on a string equality basis, which will fail with things like symlinks or relative paths. We should be recommending people use std::fs::canonicalize to avoid mistakes.
Advantage
Using canonicalize on a Path makes it so that there are no possibilities of paths that are supposed to be equal ever being considered different.
Drawbacks
No response
Example
let p = std::path::Path::new("foo/../foo");
p == Path::new("foo");
p == "foo";
Could be written as:
std::fs::canonicalize(p) == Path::new("foo");
std::fs::canonicalize(p) == "foo";
Comparison with existing lints
No response
Additional Context
This is one of the bugs found in uutils by Canonical's audit: https://corrode.dev/blog/bugs-rust-wont-catch/#string-equality-on-paths-is-not-the-same-as-filesystem-identity
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by locating Clippy's existing lints for Path comparisons and review the two example comparisons alongside the canonicalize recommendation. Done means the lint's scope, applicability, and behavior for these cases are defined and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100