checksum plumbing (#438)

This commit is contained in:
Michael Quigley 2023-12-06 17:13:45 -05:00
parent e1d4079bb1
commit fa9f77bd1d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 15 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import (
"crypto/sha512"
"encoding/xml"
"fmt"
"github.com/sirupsen/logrus"
"io"
"io/fs"
"net/http"
@ -121,7 +122,9 @@ func (f *webdavFile) checksum() (string, error) {
if _, err := io.Copy(hash, file); err != nil {
return "", err
}
return fmt.Sprintf("%x", hash.Sum(nil)), nil
sha512 := fmt.Sprintf("%x", hash.Sum(nil))
logrus.Infof("%v = %v", f.name, sha512)
return sha512, nil
}
func (f *webdavFile) updateModtime(path string, modtime time.Time) error {

View File

@ -97,6 +97,7 @@ type props struct {
ContentType string `xml:"DAV: prop>getcontenttype,omitempty"`
ETag string `xml:"DAV: prop>getetag,omitempty"`
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
Checksum string `xml:"zrok: prop>checksum,omitempty"`
}
type Response struct {
@ -159,7 +160,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
}
err := c.propfind(path, false,
`<d:propfind xmlns:d='DAV:'>
`<d:propfind xmlns:d='DAV:' xmlns:z='zrok:'>
<d:prop>
<d:displayname/>
<d:resourcetype/>
@ -167,6 +168,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
<d:getcontenttype/>
<d:getetag/>
<d:getlastmodified/>
<z:lastmodified/>
<z:checksum/>
</d:prop>
</d:propfind>`,
&Response{},
@ -211,7 +214,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
}
err := c.propfind(path, true,
`<d:propfind xmlns:d='DAV:'>
`<d:propfind xmlns:d='DAV:' xmlns:z='zrok:'>
<d:prop>
<d:displayname/>
<d:resourcetype/>
@ -219,6 +222,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
<d:getcontenttype/>
<d:getetag/>
<d:getlastmodified/>
<z:checksum/>
</d:prop>
</d:propfind>`,
&Response{},

View File

@ -15,6 +15,7 @@ type File struct {
modified time.Time
etag string
isdir bool
checksum string
}
// Path returns the full path of a file
@ -62,6 +63,10 @@ func (f File) IsDir() bool {
return f.isdir
}
func (f File) Checksum() string {
return f.checksum
}
// Sys ????
func (f File) Sys() interface{} {
return nil