mirror of
https://github.com/openziti/zrok.git
synced 2025-01-11 00:18:43 +01:00
files to copy (#438)
This commit is contained in:
parent
57c5a9977e
commit
e6aa1420be
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openziti/zrok/util/sync"
|
"github.com/openziti/zrok/util/sync"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,18 +30,10 @@ func (cmd *copyFromCommand) run(_ *cobra.Command, args []string) {
|
|||||||
target = args[1]
|
target = args[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
t := sync.NewFilesystemTarget(&sync.FilesystemTargetConfig{
|
dst := sync.NewFilesystemTarget(&sync.FilesystemTargetConfig{
|
||||||
Root: target,
|
Root: target,
|
||||||
})
|
})
|
||||||
destTree, err := t.Inventory()
|
src, err := sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for _, f := range destTree {
|
|
||||||
logrus.Infof("<- %v [%v, %v, %v]", f.Path, f.Size, f.Modified, f.ETag)
|
|
||||||
}
|
|
||||||
|
|
||||||
s, err := sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{
|
|
||||||
URL: args[0],
|
URL: args[0],
|
||||||
Username: "",
|
Username: "",
|
||||||
Password: "",
|
Password: "",
|
||||||
@ -50,11 +41,8 @@ func (cmd *copyFromCommand) run(_ *cobra.Command, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
srcTree, err := s.Inventory()
|
|
||||||
if err != nil {
|
if err := sync.Synchronize(src, dst); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for _, f := range srcTree {
|
|
||||||
logrus.Infof("-> %v [%v, %v, %v]", f.Path, f.Size, f.Modified, f.ETag)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
41
util/sync/synchronizer.go
Normal file
41
util/sync/synchronizer.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package sync
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Synchronize(src, dst Target) error {
|
||||||
|
srcTree, err := src.Inventory()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating source inventory")
|
||||||
|
}
|
||||||
|
|
||||||
|
dstTree, err := dst.Inventory()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating destination inventory")
|
||||||
|
}
|
||||||
|
|
||||||
|
dstIndex := make(map[string]*Object)
|
||||||
|
for _, f := range dstTree {
|
||||||
|
dstIndex[f.Path] = f
|
||||||
|
}
|
||||||
|
|
||||||
|
var copyList []*Object
|
||||||
|
for _, srcF := range srcTree {
|
||||||
|
if dstF, found := dstIndex[srcF.Path]; found {
|
||||||
|
if dstF.ETag != srcF.ETag {
|
||||||
|
copyList = append(copyList, srcF)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
copyList = append(copyList, srcF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("files to copy:")
|
||||||
|
for _, copy := range copyList {
|
||||||
|
logrus.Infof("-> %v", copy.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user