Skip to content

Commit ecaf74a

Browse files
committed
Rollup merge of rust-lang#22742 - alexcrichton:issue-22737, r=aturon
If the filename for a path is `None` then we know that the creation of the parent directory created the whole path so there's no need to retry the call to `create_dir`. Closes rust-lang#22737
2 parents 6c6f231 + 79bf783 commit ecaf74a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libstd/fs/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ pub fn create_dir_all<P: AsPath + ?Sized>(path: &P) -> io::Result<()> {
544544
Some(p) if p != path => try!(create_dir_all(p)),
545545
_ => {}
546546
}
547-
create_dir(path)
547+
// If the file name of the given `path` is blank then the creation of the
548+
// parent directory will have taken care of the whole path for us, so we're
549+
// good to go.
550+
if path.file_name().is_none() {
551+
Ok(())
552+
} else {
553+
create_dir(path)
554+
}
548555
}
549556

550557
/// Remove an existing, empty directory
@@ -1504,4 +1511,11 @@ mod tests {
15041511
check!(fs::set_permissions(&path, perm));
15051512
check!(fs::remove_file(&path));
15061513
}
1514+
1515+
#[test]
1516+
fn mkdir_trailing_slash() {
1517+
let tmpdir = tmpdir();
1518+
let path = tmpdir.join("file");
1519+
check!(fs::create_dir_all(&path.join("a/")));
1520+
}
15071521
}

0 commit comments

Comments
 (0)