Skip to content

Commit

Permalink
Rollup merge of rust-lang#22742 - alexcrichton:issue-22737, r=aturon
Browse files Browse the repository at this point in the history
 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
  • Loading branch information
Manishearth committed Feb 25, 2015
2 parents 6c6f231 + 79bf783 commit ecaf74a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libstd/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,14 @@ pub fn create_dir_all<P: AsPath + ?Sized>(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
Expand Down Expand Up @@ -1504,4 +1511,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/")));
}
}

0 comments on commit ecaf74a

Please sign in to comment.