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
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::canonicalizeto avoid mistakes.Advantage
Using
canonicalizeon aPathmakes it so that there are no possibilities of paths that are supposed to be equal ever being considered different.Drawbacks
No response
Example
Could be written as:
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