From: Dawid Ciężarkiewicz Date: Wed, 15 Mar 2017 05:03:00 +0000 (-0700) Subject: Fix `create_dir_all("")` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b5d590b3f0483bc943df8f59011b85500456d748;p=rust.git Fix `create_dir_all("")` Add a test for `""` and `"."`. --- diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 59a6a99201f..cc9df743ef1 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1775,6 +1775,10 @@ fn _create(&self, path: &Path) -> io::Result<()> { } fn create_dir_all(&self, path: &Path) -> io::Result<()> { + if path == Path::new("") { + return Ok(()) + } + match self.inner.mkdir(path) { Ok(()) => return Ok(()), Err(ref e) if e.kind() == io::ErrorKind::NotFound => {} @@ -2302,6 +2306,16 @@ fn recursive_mkdir_slash() { check!(fs::create_dir_all(&Path::new("/"))); } + #[test] + fn recursive_mkdir_dot() { + check!(fs::create_dir_all(&Path::new("."))); + } + + #[test] + fn recursive_mkdir_empty() { + check!(fs::create_dir_all(&Path::new(""))); + } + #[test] fn recursive_rmdir() { let tmpdir = tmpdir();