From 410e447c49a79a059750c767639a8b0d59dd55e9 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Wed, 16 May 2018 23:39:37 +0200 Subject: [PATCH] simplify 409 write error handler --- README.md | 2 +- client.go | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 79bdd9f..95f57dd 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error ``` Write writes data to a given path -#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7261:7341#L344) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7193:7273#L340) ``` go func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error ``` diff --git a/client.go b/client.go index 9b4b3d1..d471884 100644 --- a/client.go +++ b/client.go @@ -323,18 +323,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error { return nil case 409: - if idx := strings.LastIndex(path, "/"); idx == -1 { - // faulty root - return newPathError("Write", path, 500) - } else { - if err := c.MkdirAll(path[0:idx+1], 0755); err == nil { + if i := strings.LastIndex(path, "/"); i > -1 { + if err := c.MkdirAll(path[0:i+1], 0755); err == nil { s = c.put(path, bytes.NewReader(data)) - if s == 200 || s == 201 { + if s == 200 || s == 201 || s == 204 { return nil } } } - } return newPathError("Write", path, s)