simplify 409 write error handler
This commit is contained in:
parent
65a34986d4
commit
410e447c49
@ -216,7 +216,7 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error
|
|||||||
```
|
```
|
||||||
Write writes data to a given path
|
Write writes data to a given path
|
||||||
|
|
||||||
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7261:7341#L344)
|
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7193:7273#L340)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
|
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
|
||||||
```
|
```
|
||||||
|
10
client.go
10
client.go
@ -323,18 +323,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
case 409:
|
case 409:
|
||||||
if idx := strings.LastIndex(path, "/"); idx == -1 {
|
if i := strings.LastIndex(path, "/"); i > -1 {
|
||||||
// faulty root
|
if err := c.MkdirAll(path[0:i+1], 0755); err == nil {
|
||||||
return newPathError("Write", path, 500)
|
|
||||||
} else {
|
|
||||||
if err := c.MkdirAll(path[0:idx+1], 0755); err == nil {
|
|
||||||
s = c.put(path, bytes.NewReader(data))
|
s = c.put(path, bytes.NewReader(data))
|
||||||
if s == 200 || s == 201 {
|
if s == 200 || s == 201 || s == 204 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPathError("Write", path, s)
|
return newPathError("Write", path, s)
|
||||||
|
Loading…
Reference in New Issue
Block a user