From 45a56c2115b39d097912d9d325a46c4dd4ec8533 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Fri, 13 Jul 2018 12:11:56 +0200 Subject: [PATCH 1/4] cmd: remove Connect() due to #16 --- cmd/gowebdav/main.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/gowebdav/main.go b/cmd/gowebdav/main.go index c5fe1ec..cf0e945 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) From 28039fda22154a8802b9dce42c9efac4adecc69a Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Fri, 13 Jul 2018 12:12:09 +0200 Subject: [PATCH 2/4] fmt --- digestAuth.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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, ), From 83e3d1e31ef0851e3138ecf23a8b5272a7efe9c8 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Sat, 14 Jul 2018 02:48:30 +0300 Subject: [PATCH 3/4] Creating parent collection method was added (#22) * method for creating parent collection was added to Client struct "func (c *Client) createParentCollection(itemPath string) error" was added to request.go file * using Client's method to create parent collection in following methods: Client.Write() Client.WriteStream() Client.copymove() deadlock is impossible in method Client.copymove() because of paragraph #6 section 9.8.5 (https://tools.ietf.org/html/rfc4918#section-9.8.5) and paragraph #6 section 9.9.4 (https://tools.ietf.org/html/rfc4918#section-9.9.4) of RFC 4918 (https://tools.ietf.org/html/rfc4918) * install dependencies script was added to Travis-CI file * testing was added to Travis-CI file * error wrapping was removed from Client.put() method * using an early return on error in case of 409 in Client.Write() method --- .travis.yml | 6 ++++++ client.go | 23 +++++++++++++++-------- requests.go | 13 ++++++++++++- 3 files changed, 33 insertions(+), 9 deletions(-) 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/client.go b/client.go index 59525e3..40990ba 100644 --- a/client.go +++ b/client.go @@ -346,13 +346,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error { return nil case 409: - 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 || 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 } } @@ -361,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 { - // TODO check if parent collection exists + + 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/requests.go b/requests.go index 73db2c8..7a9981d 100644 --- a/requests.go +++ b/requests.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "strings" + "path" ) func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) { @@ -133,7 +134,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: - // TODO create dst path + err := c.createParentCollection(newpath) + if err != nil { + return err + } + + return c.copymove(method, oldpath, newpath, overwrite) } return newPathError(method, oldpath, s) @@ -148,3 +154,8 @@ func (c *Client) put(path string, stream io.Reader) int { return rs.StatusCode } + +func (c *Client) createParentCollection(itemPath string) (err error) { + parentPath := path.Dir(itemPath) + return c.MkdirAll(parentPath, 0755) +} From 3cd755d6c4753083fdfcd45b71e88100bf8f2057 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Sat, 14 Jul 2018 01:55:58 +0200 Subject: [PATCH 4/4] make check api --- README.md | 2 +- requests.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/requests.go b/requests.go index 7a9981d..581c08c 100644 --- a/requests.go +++ b/requests.go @@ -5,8 +5,8 @@ import ( "fmt" "io" "net/http" - "strings" "path" + "strings" ) func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {