diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 8df809264a6dd..4aa6657baa52a 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -3742,6 +3742,11 @@ impl DirBuilder { return Ok(()); } + // For certain platforms, a path like "/tmp/foo/.", while the "/tmp" directory exists, + // the mkdir function may produce a `NotFound` error on that path instead of succeeding + // due to viewing the "foo" and "." as two separate missing components. + // See https://github.com/rust-lang/rust/issues/162243 + let path = path.components().as_path(); let ancestors = path.ancestors(); let mut uncreated_dirs = 0; diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index dab1df38aa1f5..22c57aee5ff20 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -943,6 +943,14 @@ fn recursive_mkdir() { assert!(dir.is_dir()) } +#[test] +fn recursive_mkdir_with_trailing_cur_dir() { + let tmpdir = tmpdir(); + let dir = tmpdir.join("foo").join("."); + check!(fs::create_dir_all(&dir)); + assert!(dir.is_dir()) +} + #[test] fn recursive_mkdir_failure() { let tmpdir = tmpdir();