From ccf7a336ed6c51fb4d79357be6549df13b5f2e2f Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Fri, 11 Apr 2025 11:02:26 -0700 Subject: Fix error messages and special case empty path --- ccp.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'ccp.go') diff --git a/ccp.go b/ccp.go index 8ddd838..bfcfc6d 100644 --- a/ccp.go +++ b/ccp.go @@ -173,6 +173,17 @@ func splitHostPath(target string) (string, string) { return target[:i], target[i+1:] } +func toFSPath(target string, sftpHosts map[string]*sftpfs.FS) cp.FSPath { + host, path := splitHostPath(target) + if host == "" { + return cp.FSPath{FS: osfs.FS{}, Path: path} + } + if path == "" { + path = "." + } + return cp.FSPath{FS: sftpHosts[host], Path: path} +} + func run() error { args := flag.Args() if len(args) < 2 { @@ -194,20 +205,9 @@ func run() error { } srcs := make([]cp.FSPath, len(srcTargets)) for i, tgt := range srcTargets { - host, path := splitHostPath(tgt) - if host == "" { - srcs[i] = cp.FSPath{FS: osfs.FS{}, Path: path} - } else { - srcs[i] = cp.FSPath{FS: sftpHosts[host], Path: path} - } - } - dstHost, dstPath := splitHostPath(dstTarget) - var dst cp.FSPath - if dstHost == "" { - dst = cp.FSPath{FS: osfs.FS{}, Path: dstPath} - } else { - dst = cp.FSPath{FS: sftpHosts[dstHost], Path: dstPath} + srcs[i] = toFSPath(tgt, sftpHosts) } + dst := toFSPath(dstTarget, sftpHosts) m := &model{ progress: progress.New(progress.WithDefaultGradient(), progress.WithoutPercentage()), copyingFiles: make(map[string]string), -- cgit v1.3.1