mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
checksum plumbing (#438)
This commit is contained in:
parent
e1d4079bb1
commit
fa9f77bd1d
@ -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 {
|
||||
|
@ -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{},
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user