diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 98c1b50a9bf14..1f41d715c4e35 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -540,7 +540,14 @@ pub fn create_dir_all(path: &P) -> io::Result<()> { Some(p) if p != path => try!(create_dir_all(p)), _ => {} } - create_dir(path) + // If the file name of the given `path` is blank then the creation of the + // parent directory will have taken care of the whole path for us, so we're + // good to go. + if path.file_name().is_none() { + Ok(()) + } else { + create_dir(path) + } } /// Remove an existing, empty directory @@ -1500,4 +1507,11 @@ mod tests { check!(fs::set_permissions(&path, perm)); check!(fs::remove_file(&path)); } + + #[test] + fn mkdir_trailing_slash() { + let tmpdir = tmpdir(); + let path = tmpdir.join("file"); + check!(fs::create_dir_all(&path.join("a/"))); + } }