rust-lang/rust-clippy

TOCTOU: call `Path::metadata` after `Path::exists`

Ouverte

#17 158 ouverte le 4 juin 2026

 (2 commentaires) (1 réaction) (1 personne assignée)Rust (1 391 forks)batch import
A-lintgood first issue

Métriques du dépôt

Stars
 (10 406 étoiles)
Métriques de merge PR
 (Merge moyen 19j 22h) (113 PRs mergées en 30 j)

Description

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

Additional Context

https://github.com/uutils/coreutils/pull/11711/changes

Guide contributeur