add MkdirAll

This commit is contained in:
Christoph Polcin 2014-10-24 11:31:16 +02:00
parent 725c5d0f14
commit 3a09040ecb
2 changed files with 31 additions and 0 deletions

View File

@ -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)

View File

@ -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 {