]> Cypherpunks repositories - gostls13.git/commitdiff
os: Fix MkdirAll("/thisdoesnotexist").
authorAlbert Strasheim <fullung@gmail.com>
Mon, 4 Apr 2011 19:45:03 +0000 (15:45 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 4 Apr 2011 19:45:03 +0000 (15:45 -0400)
Fixes #1637.

R=rsc, rh, msolo
CC=golang-dev
https://golang.org/cl/4317049

src/pkg/os/path.go
src/pkg/os/path_test.go

index b762971d9cf986e5bd1c1c281042df475c7ce5a1..318dc735bf62842844d67189e16176ae5e975117 100644 (file)
@@ -33,7 +33,7 @@ func MkdirAll(path string, perm uint32) Error {
                j--
        }
 
-       if j > 0 {
+       if j > 1 {
                // Create parent
                err = MkdirAll(path[0:j-1], perm)
                if err != nil {
index 799e3ec2fa7a231f5ee3450154953e03cdfa4f3a..d30e904fff155d94f63f9ea1cd94413ee3ae1065 100644 (file)
@@ -179,3 +179,20 @@ func TestMkdirAllWithSymlink(t *testing.T) {
                t.Errorf("MkdirAll %q: %s", path, err)
        }
 }
+
+func TestMkdirAllAtSlash(t *testing.T) {
+       if runtime.GOOS == "windows" {
+               return
+       }
+       RemoveAll("/_go_os_test")
+       err := MkdirAll("/_go_os_test/dir", 0777)
+       if err != nil {
+               pathErr, ok := err.(*PathError)
+               // common for users not to be able to write to /
+               if ok && pathErr.Error == EACCES {
+                       return
+               }
+               t.Fatalf(`MkdirAll "/_go_os_test/dir": %v`, err)
+       }
+       RemoveAll("/_go_os_test")
+}