From 57fa51b1210ac231b1d3bcf99311bef361fe4073 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 18 Dec 2023 10:06:15 +0100 Subject: [PATCH] fix webdav import Signed-off-by: jkoberg --- go.mod | 2 +- go.sum | 4 +- .../github.com/studio-b12/gowebdav/client.go | 81 ++++++++++++++----- vendor/github.com/studio-b12/gowebdav/file.go | 17 +++- vendor/modules.txt | 4 +- 5 files changed, 77 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 0aa37482fc4..758f5aefc70 100644 --- a/go.mod +++ b/go.mod @@ -349,4 +349,4 @@ require ( replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 -replace github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231123085457-ff658b6ea159 +replace github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6 diff --git a/go.sum b/go.sum index b390dc00a90..9729019f0ed 100644 --- a/go.sum +++ b/go.sum @@ -827,8 +827,8 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= -github.com/aduffeck/gowebdav v0.0.0-20231123085457-ff658b6ea159 h1:m63hhLqbqmLGGPtyTtjTdxae61d9tMbRdKvMaDHWcDs= -github.com/aduffeck/gowebdav v0.0.0-20231123085457-ff658b6ea159/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE= +github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6 h1:ws0yvsikTQdmheKINP16tBzAHdttrHwbz/q3Fgl9X1Y= +github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= diff --git a/vendor/github.com/studio-b12/gowebdav/client.go b/vendor/github.com/studio-b12/gowebdav/client.go index 4a4bb1b6ca7..99cf24adabe 100644 --- a/vendor/github.com/studio-b12/gowebdav/client.go +++ b/vendor/github.com/studio-b12/gowebdav/client.go @@ -159,47 +159,58 @@ func (p *propstat) Modified() time.Time { return time.Unix(0, 0) } +func (p *propstat) StatusCode() int { + parts := strings.Split(p.Status, " ") + if len(parts) < 2 { + return -1 + } + + code, err := strconv.Atoi(parts[1]) + if err != nil { + return -1 + } + + return code +} + type response struct { Href string `xml:"DAV: href"` Propstats []propstat `xml:"DAV: propstat"` } -func getPropstat(r *response, status string) *propstat { +func getPropstat(r *response, statuses []string) *propstat { for _, prop := range r.Propstats { - if strings.Contains(prop.Status, status) { - return &prop + for _, status := range statuses { + if strings.Contains(prop.Status, status) { + return &prop + } } } return nil } // ReadDir reads the contents of a remote directory -func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { +func (c *Client) ReadDir(path string) ([]FileInfo, error) { return c.ReadDirWithProps(path, defaultProps) } // ReadDirWithProps reads the contents of the directory at the given path, along with the specified properties. -func (c *Client) ReadDirWithProps(path string, props []string) ([]os.FileInfo, error) { - propfindprops := "" - if len(props) > 0 { - propfindprops = `` - } - - files := make([]os.FileInfo, 0) +func (c *Client) ReadDirWithProps(path string, props []string) ([]FileInfo, error) { + files := make([]FileInfo, 0) skipSelf := true parse := func(resp interface{}) error { r := resp.(*response) if skipSelf { skipSelf = false - if p := getPropstat(r, "200"); p != nil && p.Type() == "collection" { + if p := getPropstat(r, []string{"200", "425"}); p != nil && p.Type() == "collection" { r.Propstats = nil return nil } return NewPathError("ReadDir", path, 405) } - if p := getPropstat(r, "200"); p != nil { + if p := getPropstat(r, []string{"200", "425"}); p != nil { var name string if ps, err := url.PathUnescape(r.Href); err == nil { name = pathpkg.Base(ps) @@ -213,8 +224,21 @@ func (c *Client) ReadDirWithProps(path string, props []string) ([]os.FileInfo, e return nil } + propXML := "" + switch { + case len(props) > 0: + propXML += "" + for _, prop := range props { + propXML += "" + } + propXML += "" + default: + propXML += "" + } + propXML += "" + err := c.propfind(path, false, - ``+propfindprops+``, + propXML, &response{}, parse) @@ -227,28 +251,37 @@ func (c *Client) ReadDirWithProps(path string, props []string) ([]os.FileInfo, e } // Stat returns the file stats for a specified path with the default properties -func (c *Client) Stat(path string) (os.FileInfo, error) { +func (c *Client) Stat(path string) (FileInfo, error) { return c.StatWithProps(path, defaultProps) } // StatWithProps returns the FileInfo for the specified path along with the specified properties. -func (c *Client) StatWithProps(path string, props []string) (os.FileInfo, error) { +func (c *Client) StatWithProps(path string, props []string) (FileInfo, error) { var f *File parse := func(resp interface{}) error { r := resp.(*response) - if p := getPropstat(r, "200"); p != nil && f == nil { + if p := getPropstat(r, []string{"200", "425"}); p != nil && f == nil { f = newFile(".", path, p) + } else { + return NewPathError("StatWithProps", path, 404) } r.Propstats = nil return nil } - propXML := "" - for _, prop := range props { - propXML += "" + propXML := "" + switch { + case len(props) > 0: + propXML += "" + for _, prop := range props { + propXML += "" + } + propXML += "" + default: + propXML += "" } - propXML += "" + propXML += "" err := c.propfind(path, true, propXML, @@ -257,10 +290,14 @@ func (c *Client) StatWithProps(path string, props []string) (os.FileInfo, error) if err != nil { if _, ok := err.(*os.PathError); !ok { - return nil, NewPathErrorErr("ReadDir", path, err) + return nil, NewPathErrorErr("StatWithProps", path, err) } return nil, err } + + if f == nil { + return nil, NewPathError("StatWithProps", path, 404) + } return *f, err } diff --git a/vendor/github.com/studio-b12/gowebdav/file.go b/vendor/github.com/studio-b12/gowebdav/file.go index 8c5a0918926..e66d1a4ecf7 100644 --- a/vendor/github.com/studio-b12/gowebdav/file.go +++ b/vendor/github.com/studio-b12/gowebdav/file.go @@ -7,6 +7,11 @@ import ( "time" ) +type FileInfo interface { + os.FileInfo + StatusCode() int +} + // File is our structure for a given file type File struct { path string @@ -16,12 +21,13 @@ type File struct { modified time.Time etag string isdir bool - props Props + propstat propstat + status int } func newFile(path, name string, p *propstat) *File { f := &File{ - props: p.Props, + propstat: *p, } path = FixSlashes(path) @@ -30,7 +36,6 @@ func newFile(path, name string, p *propstat) *File { f.modified = p.Modified() f.etag = p.ETag() f.contentType = p.ContentType() - f.props = p.Props if p.Type() == "collection" { f.path = filepath.Clean(f.path + "/") @@ -90,7 +95,11 @@ func (f File) IsDir() bool { // Sys ???? func (f File) Sys() interface{} { - return f.props + return f.propstat.Props +} + +func (f File) StatusCode() int { + return f.propstat.StatusCode() } // String lets us see file information diff --git a/vendor/modules.txt b/vendor/modules.txt index 5e032f4cb81..df7831f25c1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1721,7 +1721,7 @@ github.com/stretchr/objx github.com/stretchr/testify/assert github.com/stretchr/testify/mock github.com/stretchr/testify/require -# github.com/studio-b12/gowebdav v0.0.0-20221015232716-17255f2e7423 => github.com/aduffeck/gowebdav v0.0.0-20231123085457-ff658b6ea159 +# github.com/studio-b12/gowebdav v0.0.0-20221015232716-17255f2e7423 => github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6 ## explicit; go 1.17 github.com/studio-b12/gowebdav # github.com/tchap/go-patricia/v2 v2.3.1 @@ -2298,4 +2298,4 @@ stash.kopano.io/kgol/oidc-go ## explicit; go 1.13 stash.kopano.io/kgol/rndm # github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 -# github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231123085457-ff658b6ea159 +# github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6