Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
8de8ce169b
@ -2,3 +2,9 @@ language: go
|
|||||||
|
|
||||||
go:
|
go:
|
||||||
- "1.x"
|
- "1.x"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go get ./...
|
||||||
|
|
||||||
|
script:
|
||||||
|
- go test -v --short ./...
|
@ -337,7 +337,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=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
|
``` 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
|
||||||
```
|
```
|
||||||
|
15
client.go
15
client.go
@ -346,21 +346,30 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
case 409:
|
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))
|
s = c.put(path, bytes.NewReader(data))
|
||||||
if s == 200 || s == 201 || s == 204 {
|
if s == 200 || s == 201 || s == 204 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return newPathError("Write", path, s)
|
return newPathError("Write", path, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteStream writes a stream
|
// WriteStream writes a stream
|
||||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error {
|
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)
|
s := c.put(path, stream)
|
||||||
|
|
||||||
switch s {
|
switch s {
|
||||||
case 200, 201, 204:
|
case 200, 201, 204:
|
||||||
return nil
|
return nil
|
||||||
|
@ -50,9 +50,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := d.NewClient(*root, *usr, *pw)
|
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)
|
cmd := getCmd(*method)
|
||||||
|
|
||||||
|
12
requests.go
12
requests.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"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)))
|
log(fmt.Sprintf(" TODO handle %s - %s multistatus result %s", method, oldpath, String(data)))
|
||||||
|
|
||||||
case 409:
|
case 409:
|
||||||
return errors.New("can not copy/move item [" + oldpath + "] to [" +
|
err := c.createParentCollection(newpath)
|
||||||
newpath + "]: destination path does not exist or wrong XML content of the request")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.copymove(method, oldpath, newpath, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPathError(method, oldpath, s)
|
return newPathError(method, oldpath, s)
|
||||||
@ -152,8 +157,7 @@ func (c *Client) put(path string, stream io.Reader) int {
|
|||||||
return rs.StatusCode
|
return rs.StatusCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Client) createParentCollection(itemPath string) (err error) {
|
func (c *Client) createParentCollection(itemPath string) (err error) {
|
||||||
parentPath := filepath.Dir(itemPath)
|
parentPath := path.Dir(itemPath)
|
||||||
return c.MkdirAll(parentPath, 0755)
|
return c.MkdirAll(parentPath, 0755)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user