rust-lang / rust-lang/rust

std::fs::create_dir_all fails on path ending with . if it does not already exist

Open
#162,243 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-io C-bug T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

std::fs::create_dir_all("/tmp/foo/.").unwrap();

I expected to see this happen: /tmp/foo is created

Instead, this happened:

Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })

If the path already exists, the call succeeds without errors.
See this play for a demo:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b93fae57ba5820c2bfeb70e7808a0ab9

Meta

Checked on both stable and nightly on play.rust-lang.org

Backtrace

thread 'main' (14) panicked at src/main.rs:4:62:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/2e2b193f8ada105f27608b7be81c293e0d7292cb/library/std/src/panicking.rs:676:5
   1: core::panicking::panic_fmt
             at /rustc/2e2b193f8ada105f27608b7be81c293e0d7292cb/library/core/src/panicking.rs:80:14
   2: core::result::unwrap_failed
             at /rustc/2e2b193f8ada105f27608b7be81c293e0d7292cb/library/core/src/result.rs:1870:5
   3: <core::result::Result<(), core::io::error::Error>>::unwrap
             at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1232:23
   4: playground::main
             at ./src/main.rs:4:62
   5: <fn() as core::ops::function::FnOnce<()>>::call_once
             at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Rust reproducer for std::fs::create_dir_all("/tmp/foo/.") on stable and nightly, then trace the filesystem entry point involved. Done means the call creates the missing /tmp/foo directory and succeeds when the path ends with a dot, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.