mirror of
https://github.com/openziti/zrok.git
synced 2025-06-25 12:12:32 +02:00
hacky proppatch support for lastmodified property (#438)
This commit is contained in:
parent
b5210a61c6
commit
ba3d1b5032
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openziti/zrok/util/sync/webdavClient"
|
"github.com/openziti/zrok/util/sync/webdavClient"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -72,5 +73,14 @@ func (t *WebDAVTarget) WriteStream(path string, stream io.Reader, mode os.FileMo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) SetModificationTime(path string, mtime time.Time) error {
|
func (t *WebDAVTarget) SetModificationTime(path string, mtime time.Time) error {
|
||||||
|
modtimeUnix := mtime.Unix()
|
||||||
|
body := "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
|
||||||
|
"<propertyupdate xmlns=\"DAV:\" xmlns:z=\"zrok:\"><set><prop><z:lastmodified>" +
|
||||||
|
fmt.Sprintf("%d", modtimeUnix) +
|
||||||
|
"</z:lastmodified></prop></set></propertyupdate>"
|
||||||
|
logrus.Infof("sending '%v'", body)
|
||||||
|
if err := t.c.Proppatch(path, body, nil, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,12 @@ type props struct {
|
|||||||
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
|
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type response struct {
|
type Response struct {
|
||||||
Href string `xml:"DAV: href"`
|
Href string `xml:"DAV: href"`
|
||||||
Props []props `xml:"DAV: propstat"`
|
Props []props `xml:"DAV: propstat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProps(r *response, status string) *props {
|
func getProps(r *Response, status string) *props {
|
||||||
for _, prop := range r.Props {
|
for _, prop := range r.Props {
|
||||||
if strings.Contains(prop.Status, status) {
|
if strings.Contains(prop.Status, status) {
|
||||||
return &prop
|
return &prop
|
||||||
@ -119,7 +119,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
files := make([]os.FileInfo, 0)
|
files := make([]os.FileInfo, 0)
|
||||||
skipSelf := true
|
skipSelf := true
|
||||||
parse := func(resp interface{}) error {
|
parse := func(resp interface{}) error {
|
||||||
r := resp.(*response)
|
r := resp.(*Response)
|
||||||
|
|
||||||
if skipSelf {
|
if skipSelf {
|
||||||
skipSelf = false
|
skipSelf = false
|
||||||
@ -169,7 +169,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
&response{},
|
&Response{},
|
||||||
parse)
|
parse)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -184,7 +184,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
func (c *Client) Stat(path string) (os.FileInfo, error) {
|
func (c *Client) Stat(path string) (os.FileInfo, error) {
|
||||||
var f *File
|
var f *File
|
||||||
parse := func(resp interface{}) error {
|
parse := func(resp interface{}) error {
|
||||||
r := resp.(*response)
|
r := resp.(*Response)
|
||||||
if p := getProps(r, "200"); p != nil && f == nil {
|
if p := getProps(r, "200"); p != nil && f == nil {
|
||||||
f = new(File)
|
f = new(File)
|
||||||
f.name = p.Name
|
f.name = p.Name
|
||||||
@ -221,7 +221,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
|
|||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
&response{},
|
&Response{},
|
||||||
parse)
|
parse)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,6 +105,26 @@ func (c *Client) propfind(path string, self bool, body string, resp interface{},
|
|||||||
return parseXML(rs.Body, resp, parse)
|
return parseXML(rs.Body, resp, parse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Proppatch(path string, body string, resp interface{}, parse func(resp interface{}) error) error {
|
||||||
|
rs, err := c.req("PROPPATCH", path, strings.NewReader(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")
|
||||||
|
// TODO add support for 'gzip,deflate;q=0.8,q=0.7'
|
||||||
|
rq.Header.Add("Accept-Encoding", "")
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rs.Body.Close()
|
||||||
|
|
||||||
|
if rs.StatusCode != 207 {
|
||||||
|
return NewPathError("PROPPATCH", path, rs.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseXML(rs.Body, resp, parse)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) doCopyMove(
|
func (c *Client) doCopyMove(
|
||||||
method string,
|
method string,
|
||||||
oldpath string,
|
oldpath string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user