add MkdirAll
This commit is contained in:
parent
725c5d0f14
commit
3a09040ecb
23
client.go
23
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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user