From b5210a61c6230d5ab6e4b8368a7e00f724b2991f Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 1 Dec 2023 13:26:54 -0500 Subject: [PATCH] support updating the lastmodtime property (#438) --- endpoints/drive/webdav/file.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/endpoints/drive/webdav/file.go b/endpoints/drive/webdav/file.go index 437d9db8..bae07af1 100644 --- a/endpoints/drive/webdav/file.go +++ b/endpoints/drive/webdav/file.go @@ -92,9 +92,22 @@ func (f *webdavFile) DeadProps() (map[xml.Name]Property, error) { return properties, nil } -func (f *webdavFile) Patch(proppatches []Proppatch) ([]Propstat, error) { +func (f *webdavFile) Patch(patches []Proppatch) ([]Propstat, error) { var stat Propstat stat.Status = http.StatusOK + for _, patch := range patches { + for _, prop := range patch.Props { + if prop.XMLName.Space == "zrok:" && prop.XMLName.Local == "lastmodified" { + modtimeUnix, err := strconv.ParseInt(string(prop.InnerXML), 10, 64) + if err != nil { + return nil, err + } + if err := f.updateModtime(f.name, time.Unix(modtimeUnix, 0)); err != nil { + return nil, err + } + } + } + } return []Propstat{stat}, nil } @@ -111,6 +124,13 @@ func (f *webdavFile) checksum() (string, error) { return fmt.Sprintf("%x", hash.Sum(nil)), nil } +func (f *webdavFile) updateModtime(path string, modtime time.Time) error { + if err := os.Chtimes(f.name, time.Now(), modtime); err != nil { + return err + } + return nil +} + // A Dir implements FileSystem using the native file system restricted to a // specific directory tree. //