mirror of
https://github.com/openziti/zrok.git
synced 2025-06-26 20:52:33 +02: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 {
|
type copyCommand struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
|
sync bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCopyCommand() *copyCommand {
|
func newCopyCommand() *copyCommand {
|
||||||
@ -27,6 +28,7 @@ func newCopyCommand() *copyCommand {
|
|||||||
}
|
}
|
||||||
command := ©Command{cmd: cmd}
|
command := ©Command{cmd: cmd}
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
|
cmd.Flags().BoolVarP(&command.sync, "sync", "s", false, "Only copy modified files (one-way synchronize)")
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) {
|
|||||||
tui.Error("error creating target", err)
|
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)
|
tui.Error("error copying", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,15 +6,18 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Synchronize(src, dst Target) error {
|
func OneWay(src, dst Target, sync bool) error {
|
||||||
srcTree, err := src.Inventory()
|
srcTree, err := src.Inventory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error creating source inventory")
|
return errors.Wrap(err, "error creating source inventory")
|
||||||
}
|
}
|
||||||
|
|
||||||
dstTree, err := dst.Inventory()
|
var dstTree []*Object
|
||||||
if err != nil {
|
if sync {
|
||||||
return errors.Wrap(err, "error creating destination inventory")
|
dstTree, err = dst.Inventory()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating destination inventory")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dstIndex := make(map[string]*Object)
|
dstIndex := make(map[string]*Object)
|
||||||
|
@ -3,6 +3,7 @@ package sync
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openziti/zrok/drives/davClient"
|
"github.com/openziti/zrok/drives/davClient"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -85,6 +86,13 @@ func (t *WebDAVTarget) Dir(path string) ([]*Object, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) Mkdir(path string) 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))
|
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/drives/davClient"
|
||||||
"github.com/openziti/zrok/environment/env_core"
|
"github.com/openziti/zrok/environment/env_core"
|
||||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -104,6 +105,13 @@ func (t *ZrokTarget) Dir(path string) ([]*Object, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ZrokTarget) Mkdir(path string) 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))
|
return t.dc.Mkdir(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user