From 8313f3f6866859af9ae3984f99bc5728f30ae544 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 10 Jan 2024 12:54:24 -0500 Subject: [PATCH] fix default source/target scheme (#438) --- cmd/zrok/copy.go | 18 +++++++++++++----- util/sync/filesystem.go | 2 ++ util/sync/zrok.go | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/zrok/copy.go b/cmd/zrok/copy.go index 53799c04..3032207f 100644 --- a/cmd/zrok/copy.go +++ b/cmd/zrok/copy.go @@ -7,6 +7,7 @@ import ( "github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/tui" "github.com/openziti/zrok/util/sync" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" ) @@ -35,6 +36,9 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) { if err != nil { tui.Error(fmt.Sprintf("invalid source URL '%v'", args[0]), err) } + if sourceUrl.Scheme == "" { + sourceUrl.Scheme = "file" + } targetStr := "file://." if len(args) == 2 { @@ -44,6 +48,9 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) { if err != nil { tui.Error(fmt.Sprintf("invalid target URL '%v'", targetStr), err) } + if targetUrl.Scheme == "" { + targetUrl.Scheme = "file" + } root, err := environment.LoadRoot() if err != nil { @@ -97,15 +104,16 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) { fmt.Println("copy complete!") } -func (cmd *copyCommand) createTarget(t *url.URL, root env_core.Root) (sync.Target, error) { - switch t.Scheme { +func (cmd *copyCommand) createTarget(url *url.URL, root env_core.Root) (sync.Target, error) { + switch url.Scheme { case "file": - return sync.NewFilesystemTarget(&sync.FilesystemTargetConfig{Root: t.Path}), nil + logrus.Infof("%v", url) + return sync.NewFilesystemTarget(&sync.FilesystemTargetConfig{Root: url.Path}), nil case "zrok": - return sync.NewZrokTarget(&sync.ZrokTargetConfig{URL: t, Root: root}) + return sync.NewZrokTarget(&sync.ZrokTargetConfig{URL: url, Root: root}) default: - return sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{URL: t, Username: "", Password: ""}) + return sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{URL: url, Username: "", Password: ""}) } } diff --git a/util/sync/filesystem.go b/util/sync/filesystem.go index b4fa7c01..5437ba74 100644 --- a/util/sync/filesystem.go +++ b/util/sync/filesystem.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/openziti/zrok/drives/davServer" + "github.com/sirupsen/logrus" "io" "io/fs" "os" @@ -22,6 +23,7 @@ type FilesystemTarget struct { } func NewFilesystemTarget(cfg *FilesystemTargetConfig) *FilesystemTarget { + logrus.Infof("root = %v", cfg.Root) root := os.DirFS(cfg.Root) return &FilesystemTarget{cfg: cfg, root: root} } diff --git a/util/sync/zrok.go b/util/sync/zrok.go index 737aa164..ba938126 100644 --- a/util/sync/zrok.go +++ b/util/sync/zrok.go @@ -49,7 +49,7 @@ func NewZrokTarget(cfg *ZrokTargetConfig) (*ZrokTarget, error) { } func (t *ZrokTarget) Inventory() ([]*Object, error) { - fis, err := t.dc.Readdir(context.Background(), "", true) + fis, err := t.dc.Readdir(context.Background(), "/", true) if err != nil { return nil, err }