Skip to content

Commit b5d590b

Browse files
committed
Fix create_dir_all("")
Add a test for `""` and `"."`.
1 parent bcae6a3 commit b5d590b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/fs.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,10 @@ impl DirBuilder {
17751775
}
17761776

17771777
fn create_dir_all(&self, path: &Path) -> io::Result<()> {
1778+
if path == Path::new("") {
1779+
return Ok(())
1780+
}
1781+
17781782
match self.inner.mkdir(path) {
17791783
Ok(()) => return Ok(()),
17801784
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
@@ -2302,6 +2306,16 @@ mod tests {
23022306
check!(fs::create_dir_all(&Path::new("/")));
23032307
}
23042308

2309+
#[test]
2310+
fn recursive_mkdir_dot() {
2311+
check!(fs::create_dir_all(&Path::new(".")));
2312+
}
2313+
2314+
#[test]
2315+
fn recursive_mkdir_empty() {
2316+
check!(fs::create_dir_all(&Path::new("")));
2317+
}
2318+
23052319
#[test]
23062320
fn recursive_rmdir() {
23072321
let tmpdir = tmpdir();

0 commit comments

Comments
 (0)