about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-02-25 10:29:53 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-02-25 10:29:53 +0530
commitecaf74ab3b8f67e9b5fe74c34c1beee71a22da88 (patch)
tree96ae63ef7fefe96260ec870dbafa212a84c139a7 /src/libstd
parent6c6f2317bae63261123cd94ebe214e80fb6ad78e (diff)
parent79bf783ebf41c756641e90f4295fbf98cd8a11ba (diff)
downloadrust-ecaf74ab3b8f67e9b5fe74c34c1beee71a22da88.tar.gz
rust-ecaf74ab3b8f67e9b5fe74c34c1beee71a22da88.zip
Rollup merge of #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 #22737
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs/mod.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs
index aa211758621..3c9eef8c30f 100644
--- a/src/libstd/fs/mod.rs
+++ b/src/libstd/fs/mod.rs
@@ -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
@@ -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/")));
+    }
 }