]> git.lizzy.rs Git - rust.git/commitdiff
Fix `create_dir_all("")`
authorDawid Ciężarkiewicz <dpc@dpc.pw>
Wed, 15 Mar 2017 05:03:00 +0000 (22:03 -0700)
committerDawid Ciężarkiewicz <dpc@dpc.pw>
Sat, 18 Mar 2017 03:15:05 +0000 (20:15 -0700)
Add a test for `""` and `"."`.

src/libstd/fs.rs

index 59a6a99201f1e3dd374cd0f90abd8fdb1940e715..cc9df743ef1daab47dba84f557b917c15fc461b7 100644 (file)
@@ -1775,6 +1775,10 @@ fn _create(&self, path: &Path) -> io::Result<()> {
     }
 
     fn create_dir_all(&self, path: &Path) -> io::Result<()> {
+        if path == Path::new("") {
+            return Ok(())
+        }
+
         match self.inner.mkdir(path) {
             Ok(()) => return Ok(()),
             Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
@@ -2302,6 +2306,16 @@ fn recursive_mkdir_slash() {
         check!(fs::create_dir_all(&Path::new("/")));
     }
 
+    #[test]
+    fn recursive_mkdir_dot() {
+        check!(fs::create_dir_all(&Path::new(".")));
+    }
+
+    #[test]
+    fn recursive_mkdir_empty() {
+        check!(fs::create_dir_all(&Path::new("")));
+    }
+
     #[test]
     fn recursive_rmdir() {
         let tmpdir = tmpdir();