rust-lang/rust-clippy

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

オープン

#17,158 opened on 2026/06/04

 (2 件のコメント) (1 件のリアクション) (1 人の担当者)Rust (1,391 件のフォーク)batch import
A-lintgood first issue

Repository metrics

Stars
 (10,406 個のスター)
PR merge metrics
 (平均マージ 19d 22h) (30d で 113 merged PRs)

説明

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

コントリビューターガイド