diff options
author | Albert Strasheim <fullung@gmail.com> | 2011-04-04 15:45:03 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-04-04 15:45:03 -0400 |
commit | 492039ae7fd4ac034b4d47b26b438762d59b53b9 (patch) | |
tree | 807cc74d1114da02f19b60cfbe2a4c8a97c63aa1 | |
parent | 5a59b9eba31bc2f0999bf0735b66cf9c7c968944 (diff) | |
download | go-492039ae7fd4ac034b4d47b26b438762d59b53b9.tar.gz go-492039ae7fd4ac034b4d47b26b438762d59b53b9.zip |
os: Fix MkdirAll("/thisdoesnotexist").
Fixes #1637.
R=rsc, rh, msolo
CC=golang-dev
https://golang.org/cl/4317049
-rw-r--r-- | src/pkg/os/path.go | 2 | ||||
-rw-r--r-- | src/pkg/os/path_test.go | 17 |
2 files changed, 18 insertions, 1 deletions
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") +} |