support updating the lastmodtime property (#438)

This commit is contained in:
Michael Quigley 2023-12-01 13:26:54 -05:00
parent d955a77af7
commit b5210a61c6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -92,9 +92,22 @@ func (f *webdavFile) DeadProps() (map[xml.Name]Property, error) {
return properties, nil return properties, nil
} }
func (f *webdavFile) Patch(proppatches []Proppatch) ([]Propstat, error) { func (f *webdavFile) Patch(patches []Proppatch) ([]Propstat, error) {
var stat Propstat var stat Propstat
stat.Status = http.StatusOK 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 return []Propstat{stat}, nil
} }
@ -111,6 +124,13 @@ func (f *webdavFile) checksum() (string, error) {
return fmt.Sprintf("%x", hash.Sum(nil)), nil 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 // A Dir implements FileSystem using the native file system restricted to a
// specific directory tree. // specific directory tree.
// //