From: Albert Strasheim Date: Mon, 4 Apr 2011 19:45:03 +0000 (-0400) Subject: os: Fix MkdirAll("/thisdoesnotexist"). X-Git-Tag: weekly.2011-04-04~13 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=492039ae7fd4ac034b4d47b26b438762d59b53b9;p=gostls13.git os: Fix MkdirAll("/thisdoesnotexist"). Fixes #1637. R=rsc, rh, msolo CC=golang-dev https://golang.org/cl/4317049 --- diff --git a/src/pkg/os/path.go b/src/pkg/os/path.go index b762971d9c..318dc735bf 100644 --- a/src/pkg/os/path.go +++ b/src/pkg/os/path.go @@ -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 { diff --git a/src/pkg/os/path_test.go b/src/pkg/os/path_test.go index 799e3ec2fa..d30e904fff 100644 --- a/src/pkg/os/path_test.go +++ b/src/pkg/os/path_test.go @@ -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") +}