mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
fix default source/target scheme (#438)
This commit is contained in:
parent
999b65fc6c
commit
8313f3f686
@ -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: ""})
|
||||
}
|
||||
}
|
||||
|
@ -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}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user