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" "crypto/sha512"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"github.com/sirupsen/logrus"
"io" "io"
"io/fs" "io/fs"
"net/http" "net/http"
@ -121,7 +122,9 @@ func (f *webdavFile) checksum() (string, error) {
if _, err := io.Copy(hash, file); err != nil { if _, err := io.Copy(hash, file); err != nil {
return "", err 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 { 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"` ContentType string `xml:"DAV: prop>getcontenttype,omitempty"`
ETag string `xml:"DAV: prop>getetag,omitempty"` ETag string `xml:"DAV: prop>getetag,omitempty"`
Modified string `xml:"DAV: prop>getlastmodified,omitempty"` Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
Checksum string `xml:"zrok: prop>checksum,omitempty"`
} }
type Response struct { type Response struct {
@ -159,7 +160,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
} }
err := c.propfind(path, false, err := c.propfind(path, false,
`<d:propfind xmlns:d='DAV:'> `<d:propfind xmlns:d='DAV:' xmlns:z='zrok:'>
<d:prop> <d:prop>
<d:displayname/> <d:displayname/>
<d:resourcetype/> <d:resourcetype/>
@ -167,6 +168,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
<d:getcontenttype/> <d:getcontenttype/>
<d:getetag/> <d:getetag/>
<d:getlastmodified/> <d:getlastmodified/>
<z:lastmodified/>
<z:checksum/>
</d:prop> </d:prop>
</d:propfind>`, </d:propfind>`,
&Response{}, &Response{},
@ -211,7 +214,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
} }
err := c.propfind(path, true, err := c.propfind(path, true,
`<d:propfind xmlns:d='DAV:'> `<d:propfind xmlns:d='DAV:' xmlns:z='zrok:'>
<d:prop> <d:prop>
<d:displayname/> <d:displayname/>
<d:resourcetype/> <d:resourcetype/>
@ -219,6 +222,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
<d:getcontenttype/> <d:getcontenttype/>
<d:getetag/> <d:getetag/>
<d:getlastmodified/> <d:getlastmodified/>
<z:checksum/>
</d:prop> </d:prop>
</d:propfind>`, </d:propfind>`,
&Response{}, &Response{},

View File

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