rust-lang/rust-clippy
Auf GitHub ansehenTOCTOU: call `Path::metadata` after `Path::exists`
Open
#17.158 geöffnet am 4. Juni 2026
A-lintgood first issue
Repository-Metriken
- Stars
- (10.406 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 16T 6h) (79 gemergte PRs in 30 T)
Beschreibung
What it does
Detect when calling Path::exists followed by another operation that would cause a new syscall to be used on the path, like Path::metadata.
Advantage
Remove a source of TOCTOU bugs.
Drawbacks
No response
Example
if new_path.exists() {
let md = new_path.metadata().unwrap();
Could be written as:
if let Ok(md) = new_path.metadata() {
Comparison with existing lints
No response