feat(ocis): bump gowebdav
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
+40
-4
@@ -3,6 +3,7 @@ package gowebdav
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -159,6 +160,10 @@ func (p *propstat) Modified() time.Time {
|
||||
return time.Unix(0, 0)
|
||||
}
|
||||
|
||||
func (p *propstat) Lock() string {
|
||||
return p.Props.GetString(xml.Name{Space: "DAV:", Local: "lockdiscovery"})
|
||||
}
|
||||
|
||||
func (p *propstat) StatusCode() int {
|
||||
parts := strings.Split(p.Status, " ")
|
||||
if len(parts) < 2 {
|
||||
@@ -380,6 +385,37 @@ func (c *Client) Copy(oldpath, newpath string, overwrite bool) error {
|
||||
return c.copymove("COPY", oldpath, newpath, overwrite)
|
||||
}
|
||||
|
||||
// GetLock gets a lock
|
||||
func (c *Client) GetLock(path string) (string, error) {
|
||||
fi, err := c.Stat(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
f, ok := fi.(File)
|
||||
if !ok {
|
||||
// This won't happen unless implementation is changed
|
||||
return "", errors.New("Stat did not return a File")
|
||||
}
|
||||
|
||||
return f.Lock(), nil
|
||||
}
|
||||
|
||||
// Lock locks a file
|
||||
func (c *Client) Lock(path string, token string) error {
|
||||
return c.lock(path, token, false)
|
||||
}
|
||||
|
||||
// RefreshLock refreshes a lock
|
||||
func (c *Client) RefreshLock(path string, token string) error {
|
||||
return c.lock(path, token, true)
|
||||
}
|
||||
|
||||
// Unlock unlocks a file
|
||||
func (c *Client) Unlock(path string, token string) error {
|
||||
return c.unlock(path, token)
|
||||
}
|
||||
|
||||
// Read reads the contents of a remote file
|
||||
func (c *Client) Read(path string) ([]byte, error) {
|
||||
var stream io.ReadCloser
|
||||
@@ -456,7 +492,7 @@ func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadClos
|
||||
|
||||
// Write writes data to a given path
|
||||
func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
||||
s, err := c.put(path, bytes.NewReader(data))
|
||||
s, err := c.put(path, bytes.NewReader(data), "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -472,7 +508,7 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
s, err = c.put(path, bytes.NewReader(data))
|
||||
s, err = c.put(path, bytes.NewReader(data), "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -485,14 +521,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
||||
}
|
||||
|
||||
// WriteStream writes a stream
|
||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) {
|
||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode, locktoken string) (err error) {
|
||||
|
||||
err = c.createParentCollection(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := c.put(path, stream)
|
||||
s, err := c.put(path, stream, locktoken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+6
-1
@@ -31,7 +31,7 @@ func newFile(path, name string, p *propstat) *File {
|
||||
}
|
||||
path = FixSlashes(path)
|
||||
|
||||
f.name = name
|
||||
f.name = filepath.Base(name)
|
||||
f.path = filepath.Clean(filepath.Join(path, f.name))
|
||||
f.modified = p.Modified()
|
||||
f.etag = p.ETag()
|
||||
@@ -98,6 +98,11 @@ func (f File) Sys() interface{} {
|
||||
return f.propstat.Props
|
||||
}
|
||||
|
||||
// Lock returns the files lock
|
||||
func (f File) Lock() string {
|
||||
return f.propstat.Lock()
|
||||
}
|
||||
|
||||
func (f File) StatusCode() int {
|
||||
return f.propstat.StatusCode()
|
||||
}
|
||||
|
||||
+61
-2
@@ -105,6 +105,63 @@ func (c *Client) propfind(path string, self bool, body string, resp interface{},
|
||||
return parseXML(rs.Body, resp, parse)
|
||||
}
|
||||
|
||||
func (c *Client) lock(path string, token string, refresh bool) error {
|
||||
var body io.Reader
|
||||
if !refresh {
|
||||
b := strings.Builder{}
|
||||
|
||||
// build the lockinfo xml
|
||||
b.WriteString("<D:lockinfo>")
|
||||
// always use an exclusive lock
|
||||
b.WriteString("<D:lockscope><D:exclusive/></D:lockscope>")
|
||||
// always use a write lock
|
||||
b.WriteString("<D:locktype><D:write/></D:locktype>")
|
||||
// add the lock token
|
||||
b.WriteString("<d:locktoken><d:href>")
|
||||
b.WriteString(token)
|
||||
b.WriteString("</d:href></d:locktoken>")
|
||||
// close the lockinfo xml
|
||||
b.WriteString("</D:lockinfo>")
|
||||
|
||||
body = strings.NewReader(b.String())
|
||||
}
|
||||
|
||||
rs, err := c.req("LOCK", path, body, func(rq *http.Request) {
|
||||
rq.Header.Add("Content-Type", "application/xml;charset=UTF-8")
|
||||
rq.Header.Add("Accept", "application/xml,text/xml")
|
||||
rq.Header.Add("Accept-Charset", "utf-8")
|
||||
rq.Header.Add("Accept-Encoding", "")
|
||||
if refresh {
|
||||
rq.Header.Add("If", "("+token+")")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rs.Body.Close()
|
||||
|
||||
if rs.StatusCode != 200 {
|
||||
return NewPathError("LOCK", path, rs.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) unlock(path string, token string) error {
|
||||
rs, err := c.req("UNLOCK", path, nil, func(rq *http.Request) {
|
||||
rq.Header.Add("Lock-Token", "<"+token+">")
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rs.Body.Close()
|
||||
|
||||
if rs.StatusCode != http.StatusNoContent {
|
||||
return NewPathError("UNLOCK", path, rs.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) doCopyMove(
|
||||
method string,
|
||||
oldpath string,
|
||||
@@ -160,8 +217,10 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
|
||||
return NewPathError(method, oldpath, s)
|
||||
}
|
||||
|
||||
func (c *Client) put(path string, stream io.Reader) (status int, err error) {
|
||||
rs, err := c.req("PUT", path, stream, nil)
|
||||
func (c *Client) put(path string, stream io.Reader, locktoken string) (status int, err error) {
|
||||
rs, err := c.req("PUT", path, stream, func(rq *http.Request) {
|
||||
rq.Header.Add("Lock-Token", "<"+locktoken+">")
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user