mirror of
https://github.com/openziti/zrok.git
synced 2025-02-02 11:29:50 +01:00
support for updating timestamps in 'driveClient' (#511)
This commit is contained in:
parent
2d16ac2056
commit
03cf7cc8b4
@ -3,9 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openziti/zrok/util/sync/driveClient"
|
"github.com/openziti/zrok/util/sync/driveClient"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -20,7 +20,7 @@ func newDavtestCommand() *davtestCommand {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "davtest",
|
Use: "davtest",
|
||||||
Short: "WebDAV testing wrapper",
|
Short: "WebDAV testing wrapper",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(2),
|
||||||
}
|
}
|
||||||
command := &davtestCommand{cmd: cmd}
|
command := &davtestCommand{cmd: cmd}
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
@ -32,11 +32,7 @@ func (cmd *davtestCommand) run(_ *cobra.Command, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fis, err := client.Readdir(context.Background(), "/", true)
|
if err := client.Touch(context.Background(), args[1], time.Now().Add(-(24 * time.Hour))); err != nil {
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for _, fi := range fis {
|
|
||||||
logrus.Infof("=> %s", fi.Path)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -205,6 +205,19 @@ func (c *Client) Create(ctx context.Context, name string) (io.WriteCloser, error
|
|||||||
return &fileWriter{pw, done}, nil
|
return &fileWriter{pw, done}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Touch(ctx context.Context, path string, mtime time.Time) error {
|
||||||
|
status, err := c.ic.Touch(ctx, path, mtime)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, resp := range status.Responses {
|
||||||
|
if resp.Err() != nil {
|
||||||
|
return resp.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) RemoveAll(ctx context.Context, name string) error {
|
func (c *Client) RemoveAll(ctx context.Context, name string) error {
|
||||||
req, err := c.ic.NewRequest(http.MethodDelete, name, nil)
|
req, err := c.ic.NewRequest(http.MethodDelete, name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -180,6 +181,35 @@ func (c *Client) PropFind(ctx context.Context, path string, depth Depth, propfin
|
|||||||
return c.DoMultiStatus(req.WithContext(ctx))
|
return c.DoMultiStatus(req.WithContext(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Touch(ctx context.Context, path string, mtime time.Time) (*MultiStatus, error) {
|
||||||
|
tstr := fmt.Sprintf("%d", mtime.Unix())
|
||||||
|
var v []RawXMLValue
|
||||||
|
for _, c := range tstr {
|
||||||
|
v = append(v, RawXMLValue{tok: xml.CharData{byte(c)}})
|
||||||
|
}
|
||||||
|
pup := &PropertyUpdate{
|
||||||
|
Set: []Set{
|
||||||
|
{
|
||||||
|
Prop: Prop{
|
||||||
|
Raw: []RawXMLValue{
|
||||||
|
*NewRawXMLElement(xml.Name{Space: "zrok:", Local: "lastmodified"}, nil, v),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
status, err := c.PropUpdate(ctx, path, pup)
|
||||||
|
return status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) PropUpdate(ctx context.Context, path string, propupd *PropertyUpdate) (*MultiStatus, error) {
|
||||||
|
req, err := c.NewXMLRequest("PROPPATCH", path, propupd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.DoMultiStatus(req.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
// PropfindFlat performs a PROPFIND request with a zero depth.
|
// PropfindFlat performs a PROPFIND request with a zero depth.
|
||||||
func (c *Client) PropFindFlat(ctx context.Context, path string, propfind *PropFind) (*Response, error) {
|
func (c *Client) PropFindFlat(ctx context.Context, path string, propfind *PropFind) (*Response, error) {
|
||||||
ms, err := c.PropFind(ctx, path, DepthZero, propfind)
|
ms, err := c.PropFind(ctx, path, DepthZero, propfind)
|
||||||
|
Loading…
Reference in New Issue
Block a user