diff --git a/.travis.yml b/.travis.yml index 1ca29c5..76bfb65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,9 @@ language: go go: - "1.x" + +install: + - go get ./... + +script: + - go test -v --short ./... \ No newline at end of file diff --git a/README.md b/README.md index 7c5b921..9283c76 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,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=7798:7878#L363) +#### func (\*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 ``` diff --git a/client.go b/client.go index dcf88a7..17459b9 100644 --- a/client.go +++ b/client.go @@ -346,11 +346,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error { return nil case 409: - if err := c.createParentCollection(path); err == nil { - s = c.put(path, bytes.NewReader(data)) - if s == 200 || s == 201 || s == 204 { - return 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 } } @@ -359,8 +362,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error { // 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 diff --git a/cmd/gowebdav/main.go b/cmd/gowebdav/main.go index c96c836..645ec85 100644 --- a/cmd/gowebdav/main.go +++ b/cmd/gowebdav/main.go @@ -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) diff --git a/digestAuth.go b/digestAuth.go index a75fdf2..dd5c844 100644 --- a/digestAuth.go +++ b/digestAuth.go @@ -77,11 +77,11 @@ func getDigestAuthorization(digestParts map[string]string) string { // These are the correct ha1 and ha2 for qop=auth. We should probably check for other types of qop. var ( - ha1 string - ha2 string + ha1 string + ha2 string nonceCount = 00000001 - cnonce = getCnonce() - response string + cnonce = getCnonce() + response string ) // 'ha1' value depends on value of "algorithm" field @@ -91,7 +91,7 @@ func getDigestAuthorization(digestParts map[string]string) string { case "MD5-sess": ha1 = getMD5( fmt.Sprintf("%s:%v:%s", - getMD5(d["username"] + ":" + d["realm"] + ":" + d["password"]), + getMD5(d["username"]+":"+d["realm"]+":"+d["password"]), nonceCount, cnonce, ), diff --git a/requests.go b/requests.go index bd42ed3..ff180de 100644 --- a/requests.go +++ b/requests.go @@ -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) }