fix default source/target scheme (#438)

This commit is contained in:
Michael Quigley 2024-01-10 12:54:24 -05:00
parent 999b65fc6c
commit 8313f3f686
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 16 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui" "github.com/openziti/zrok/tui"
"github.com/openziti/zrok/util/sync" "github.com/openziti/zrok/util/sync"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"net/url" "net/url"
) )
@ -35,6 +36,9 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) {
if err != nil { if err != nil {
tui.Error(fmt.Sprintf("invalid source URL '%v'", args[0]), err) tui.Error(fmt.Sprintf("invalid source URL '%v'", args[0]), err)
} }
if sourceUrl.Scheme == "" {
sourceUrl.Scheme = "file"
}
targetStr := "file://." targetStr := "file://."
if len(args) == 2 { if len(args) == 2 {
@ -44,6 +48,9 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) {
if err != nil { if err != nil {
tui.Error(fmt.Sprintf("invalid target URL '%v'", targetStr), err) tui.Error(fmt.Sprintf("invalid target URL '%v'", targetStr), err)
} }
if targetUrl.Scheme == "" {
targetUrl.Scheme = "file"
}
root, err := environment.LoadRoot() root, err := environment.LoadRoot()
if err != nil { if err != nil {
@ -97,15 +104,16 @@ func (cmd *copyCommand) run(_ *cobra.Command, args []string) {
fmt.Println("copy complete!") fmt.Println("copy complete!")
} }
func (cmd *copyCommand) createTarget(t *url.URL, root env_core.Root) (sync.Target, error) { func (cmd *copyCommand) createTarget(url *url.URL, root env_core.Root) (sync.Target, error) {
switch t.Scheme { switch url.Scheme {
case "file": 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": case "zrok":
return sync.NewZrokTarget(&sync.ZrokTargetConfig{URL: t, Root: root}) return sync.NewZrokTarget(&sync.ZrokTargetConfig{URL: url, Root: root})
default: default:
return sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{URL: t, Username: "", Password: ""}) return sync.NewWebDAVTarget(&sync.WebDAVTargetConfig{URL: url, Username: "", Password: ""})
} }
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/openziti/zrok/drives/davServer" "github.com/openziti/zrok/drives/davServer"
"github.com/sirupsen/logrus"
"io" "io"
"io/fs" "io/fs"
"os" "os"
@ -22,6 +23,7 @@ type FilesystemTarget struct {
} }
func NewFilesystemTarget(cfg *FilesystemTargetConfig) *FilesystemTarget { func NewFilesystemTarget(cfg *FilesystemTargetConfig) *FilesystemTarget {
logrus.Infof("root = %v", cfg.Root)
root := os.DirFS(cfg.Root) root := os.DirFS(cfg.Root)
return &FilesystemTarget{cfg: cfg, root: root} return &FilesystemTarget{cfg: cfg, root: root}
} }

View File

@ -49,7 +49,7 @@ func NewZrokTarget(cfg *ZrokTargetConfig) (*ZrokTarget, error) {
} }
func (t *ZrokTarget) Inventory() ([]*Object, 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 { if err != nil {
return nil, err return nil, err
} }