diff --git a/cmd-ls.go b/cmd-ls.go index d48905ed..9715287d 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -128,7 +128,8 @@ func runListCmd(ctx *cli.Context) { for targetURL, targetConfig := range targetURLConfigMap { // if recursive strip off the "..." newTargetURL := stripRecursiveURL(targetURL) - recursivePrefix := "" // is set when ... includes a directory, i.e. /path/to/dir... instead of path/to/dir/... + // is set when ... includes a directory, i.e. /path/to/dir... instead of path/to/dir/... + recursivePrefix := "" if isURLRecursive(targetURL) && !strings.HasSuffix(newTargetURL, string(filepath.Separator)) { recursivePrefix = filepath.Base(newTargetURL) } diff --git a/cp-url.go b/cp-url.go index c66ecbf2..385ebe22 100644 --- a/cp-url.go +++ b/cp-url.go @@ -212,7 +212,14 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *cpURLs { } // add `/` after trimming off `...` to emulate directories - sourceURL = strings.TrimSuffix(stripRecursiveURL(sourceURL), "/") + "/" + sourceURL = stripRecursiveURL(sourceURL) + // is set when ... includes a directory, i.e. /path/to/dir... instead of path/to/dir/... + recursivePrefix := "" + if !strings.HasSuffix(sourceURL, string(filepath.Separator)) { + recursivePrefix = filepath.Base(sourceURL) + } + sourceURL = strings.TrimSuffix(sourceURL, string(filepath.Separator)) + string(filepath.Separator) + sourceClient, err := source2Client(sourceURL) if err != nil { cpURLsCh <- &cpURLs{Error: iodine.New(err, nil)} @@ -286,7 +293,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *cpURLs { // Construct target path from recursive path of source without its prefix dir. newTargetURLParse := *targetURLParse - newTargetURLParse.Path = filepath.Join(newTargetURLParse.Path, + newTargetURLParse.Path = filepath.Join(newTargetURLParse.Path, recursivePrefix, strings.TrimPrefix(sourceContentParse.Path, filepath.Dir(sourceURLParse.Path))) cpURLsCh <- prepareCopyURLsTypeA(sourceContentParse.String(), newTargetURLParse.String()) } diff --git a/ls.go b/ls.go index 534651ad..8fe042d6 100644 --- a/ls.go +++ b/ls.go @@ -83,9 +83,7 @@ func doList(clnt client.Client, targetURL string, recursive bool, recursivePrefi // To be consistent we have to filter them out contentName = strings.TrimPrefix(contentName, strings.TrimSuffix(targetURL, string(filepath.Separator))+string(filepath.Separator)) - if recursivePrefix != "" { - contentName = recursivePrefix + string(filepath.Separator) + contentName - } + contentName = filepath.Join(recursivePrefix, contentName) } contentCh.Content.Name = contentName console.Println(parseContent(contentCh.Content))