Merge remote-tracking branch 'upstream/master'

This commit is contained in:
vitalii 2018-07-17 14:00:43 +03:00
commit 8de8ce169b
6 changed files with 35 additions and 19 deletions

View File

@ -2,3 +2,9 @@ language: go
go:
- "1.x"
install:
- go get ./...
script:
- go test -v --short ./...

View File

@ -337,7 +337,7 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error
```
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=7798:7878#L363)
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7752:7832#L364)
``` go
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
```

View File

@ -346,21 +346,30 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
return nil
case 409:
if err := c.createParentCollection(path); err == nil {
err := c.createParentCollection(path)
if err != nil {
return err
}
s = c.put(path, bytes.NewReader(data))
if s == 200 || s == 201 || s == 204 {
return nil
}
}
}
return newPathError("Write", path, s)
}
// WriteStream writes a stream
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error {
c.createParentCollection(path)
err := c.createParentCollection(path)
if err != nil {
return err
}
s := c.put(path, stream)
switch s {
case 200, 201, 204:
return nil

View File

@ -50,9 +50,6 @@ func main() {
}
c := d.NewClient(*root, *usr, *pw)
if err := c.Connect(); err != nil {
fail(fmt.Sprintf("Failed to connect due to: %s", err.Error()))
}
cmd := getCmd(*method)

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"path"
"strings"
"errors"
"path/filepath"
@ -135,8 +136,12 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
log(fmt.Sprintf(" TODO handle %s - %s multistatus result %s", method, oldpath, String(data)))
case 409:
return errors.New("can not copy/move item [" + oldpath + "] to [" +
newpath + "]: destination path does not exist or wrong XML content of the request")
err := c.createParentCollection(newpath)
if err != nil {
return err
}
return c.copymove(method, oldpath, newpath, overwrite)
}
return newPathError(method, oldpath, s)
@ -152,8 +157,7 @@ func (c *Client) put(path string, stream io.Reader) int {
return rs.StatusCode
}
func (c *Client) createParentCollection(itemPath string) (err error) {
parentPath := filepath.Dir(itemPath)
parentPath := path.Dir(itemPath)
return c.MkdirAll(parentPath, 0755)
}