mirror of
https://github.com/openziti/zrok.git
synced 2024-11-24 17:13:51 +01:00
'zrok copy' now supports copy and oneway sync (#438)
This commit is contained in:
parent
3b35250024
commit
e40df8c101
@ -15,7 +15,8 @@ func init() {
|
||||
}
|
||||
|
||||
type copyCommand struct {
|
||||
cmd *cobra.Command
|
||||
cmd *cobra.Command
|
||||
sync bool
|
||||
}
|
||||
|
||||
func newCopyCommand() *copyCommand {
|
||||
@ -27,6 +28,7 @@ func newCopyCommand() *copyCommand {
|
||||
}
|
||||
command := ©Command{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
cmd.Flags().BoolVarP(&command.sync, "sync", "s", false, "Only copy modified files (one-way synchronize)")
|
||||
return command
|
||||
}
|
||||
|
||||
@ -89,7 +91,7 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) {
|
||||
tui.Error("error creating target", err)
|
||||
}
|
||||
|
||||
if err := sync.Synchronize(source, target); err != nil {
|
||||
if err := sync.OneWay(source, target, cmd.sync); err != nil {
|
||||
tui.Error("error copying", err)
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,18 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func Synchronize(src, dst Target) error {
|
||||
func OneWay(src, dst Target, sync bool) 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")
|
||||
var dstTree []*Object
|
||||
if sync {
|
||||
dstTree, err = dst.Inventory()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating destination inventory")
|
||||
}
|
||||
}
|
||||
|
||||
dstIndex := make(map[string]*Object)
|
||||
|
@ -3,6 +3,7 @@ package sync
|
||||
import (
|
||||
"context"
|
||||
"github.com/openziti/zrok/drives/davClient"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -85,6 +86,13 @@ func (t *WebDAVTarget) Dir(path string) ([]*Object, error) {
|
||||
}
|
||||
|
||||
func (t *WebDAVTarget) Mkdir(path string) error {
|
||||
fi, err := t.dc.Stat(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||
if err == nil {
|
||||
if fi.IsDir {
|
||||
return nil
|
||||
}
|
||||
return errors.Errorf("'%v' already exists; not directory", path)
|
||||
}
|
||||
return t.dc.Mkdir(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/openziti/zrok/drives/davClient"
|
||||
"github.com/openziti/zrok/environment/env_core"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -104,6 +105,13 @@ func (t *ZrokTarget) Dir(path string) ([]*Object, error) {
|
||||
}
|
||||
|
||||
func (t *ZrokTarget) Mkdir(path string) error {
|
||||
fi, err := t.dc.Stat(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||
if err == nil {
|
||||
if fi.IsDir {
|
||||
return nil
|
||||
}
|
||||
return errors.Errorf("'%v' already exists; not directory", path)
|
||||
}
|
||||
return t.dc.Mkdir(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user