diff --git a/client.go b/client.go index a828436..a811164 100644 --- a/client.go +++ b/client.go @@ -143,6 +143,29 @@ func (c *Client) Mkdir(path string, _ os.FileMode) error { } } +func (c *Client) MkdirAll(path string, _ os.FileMode) error { + path = FixSlashes(path) + status := c.mkcol(path) + if status == 201 { + return nil + } else if status == 409 { + paths := strings.Split(path, "/") + sub := "/" + for _, e := range paths { + if e == "" { + continue + } + sub += e + "/" + status = c.mkcol(sub) + if status != 201 { + return newPathError("MkdirAll", sub, status) + } + } + return nil + } + + return newPathError("MkdirAll", path, status) +} func (c *Client) Read(path string) { fmt.Println("Read " + path) diff --git a/main/client.go b/main/client.go index a53f271..d65839c 100644 --- a/main/client.go +++ b/main/client.go @@ -18,6 +18,7 @@ func Fail(err interface{}) { fmt.Println(" LIST, PROPFIND:") fmt.Println(" RM, DELETE, DEL:") fmt.Println(" MKDIR, MKCOL:") + fmt.Println(" MKDIRALL, MKCOLALL:") } os.Exit(-1) } @@ -67,6 +68,13 @@ func main() { fmt.Println("MkDir: " + path) } + case "MKCOLALL", "MKDIRALL": + if err := c.MkdirAll(path, 0); err != nil { + fmt.Println(err) + } else { + fmt.Println("MkDirAll: " + path) + } + default: Fail(nil) } } else {