Skip to content

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

Description

@Raniz85

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions