1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:34:40 -07:00

os: Fix MkdirAll("/thisdoesnotexist").

Fixes #1637.

R=rsc, rh, msolo
CC=golang-dev
https://golang.org/cl/4317049
This commit is contained in:
Albert Strasheim 2011-04-04 15:45:03 -04:00 committed by Russ Cox
parent 5a59b9eba3
commit 492039ae7f
2 changed files with 18 additions and 1 deletions

View File

@ -33,7 +33,7 @@ func MkdirAll(path string, perm uint32) Error {
j-- j--
} }
if j > 0 { if j > 1 {
// Create parent // Create parent
err = MkdirAll(path[0:j-1], perm) err = MkdirAll(path[0:j-1], perm)
if err != nil { if err != nil {

View File

@ -179,3 +179,20 @@ func TestMkdirAllWithSymlink(t *testing.T) {
t.Errorf("MkdirAll %q: %s", path, err) 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")
}