mirror of
https://github.com/openziti/zrok.git
synced 2025-01-22 22:09:03 +01:00
modification time and UTC (#438)
This commit is contained in:
parent
93277a191b
commit
c397ae883b
@ -8,6 +8,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FilesystemTargetConfig struct {
|
||||
@ -52,7 +53,7 @@ func (t *FilesystemTarget) recurse(path string, d fs.DirEntry, err error) error
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
etag = fmt.Sprintf(`"%x%x"`, fi.ModTime().UnixNano(), fi.Size())
|
||||
etag = fmt.Sprintf(`"%x%x"`, fi.ModTime().UTC().UnixNano(), fi.Size())
|
||||
}
|
||||
t.tree = append(t.tree, &Object{path, fi.Size(), fi.ModTime(), etag})
|
||||
}
|
||||
@ -79,3 +80,11 @@ func (t *FilesystemTarget) WriteStream(path string, stream io.Reader, mode os.Fi
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *FilesystemTarget) SetModificationTime(path string, mtime time.Time) error {
|
||||
targetPath := filepath.Join(t.cfg.Root, path)
|
||||
if err := os.Chtimes(targetPath, time.Now(), mtime); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -17,4 +17,5 @@ type Target interface {
|
||||
Inventory() ([]*Object, error)
|
||||
ReadStream(path string) (io.ReadCloser, error)
|
||||
WriteStream(path string, stream io.Reader, mode os.FileMode) error
|
||||
SetModificationTime(path string, mtime time.Time) error
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func Synchronize(src, dst Target) error {
|
||||
var copyList []*Object
|
||||
for _, srcF := range srcTree {
|
||||
if dstF, found := dstIndex[srcF.Path]; found {
|
||||
if dstF.ETag != srcF.ETag {
|
||||
if dstF.Size != srcF.Size || dstF.Modified.UTC() != srcF.Modified.UTC() {
|
||||
copyList = append(copyList, srcF)
|
||||
}
|
||||
} else {
|
||||
@ -34,7 +34,6 @@ func Synchronize(src, dst Target) error {
|
||||
}
|
||||
|
||||
for _, target := range copyList {
|
||||
logrus.Infof("+> %v", target.Path)
|
||||
ss, err := src.ReadStream(target.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -42,6 +41,9 @@ func Synchronize(src, dst Target) error {
|
||||
if err := dst.WriteStream(target.Path, ss, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dst.SetModificationTime(target.Path, target.Modified); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("=> %v", target.Path)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WebDAVTargetConfig struct {
|
||||
@ -67,3 +68,7 @@ func (t *WebDAVTarget) ReadStream(path string) (io.ReadCloser, error) {
|
||||
func (t *WebDAVTarget) WriteStream(path string, stream io.Reader, mode os.FileMode) error {
|
||||
return t.c.WriteStream(path, stream, mode)
|
||||
}
|
||||
|
||||
func (t *WebDAVTarget) SetModificationTime(path string, mtime time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user