From a3522a29627224d25bf4f23566bd47db3e5f055b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 15 Nov 2015 22:23:28 -0800 Subject: [PATCH] cp: Fix cp command behavior for s3/bucketname/prefix... operations --- cp-url.go | 9 ++++----- url.go | 14 -------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/cp-url.go b/cp-url.go index 776215c0..7b70331e 100644 --- a/cp-url.go +++ b/cp-url.go @@ -290,11 +290,10 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { } // All OK.. We can proceed. Type B: source is a file, target is a folder and exists. - newTargetURL := client.NewURL(targetURL) - newTargetURL.Path = filepath.Join(newTargetURL.Path, - strings.TrimPrefix(sourceContent.Content.URL.Path, url2Dir(sourceURL))) - - copyURLsCh <- prepareCopyURLsTypeA(sourceContent.Content.URL.String(), newTargetURL.String()) + newSourceURL := sourceContent.Content.URL.String() + newSourceSuffix := strings.TrimPrefix(newSourceURL, sourceURL) + newTargetURL := urlJoinPath(targetURL, newSourceSuffix) + copyURLsCh <- prepareCopyURLsTypeA(sourceContent.Content.URL.String(), newTargetURL) } }(sourceURL, targetURL, copyURLsCh) return copyURLsCh diff --git a/url.go b/url.go index c0c48e8f..91fbcf5d 100644 --- a/url.go +++ b/url.go @@ -29,20 +29,6 @@ const ( recursiveSeparator = "..." ) -// just like filepath.Dir but always has a trailing url.Seperator -func url2Dir(urlStr string) string { - url := client.NewURL(urlStr) - if strings.HasSuffix(urlStr, string(url.Separator)) { - return urlStr - } - lastIndex := strings.LastIndex(urlStr, string(url.Separator)) - dirname := urlStr[:lastIndex+1] - if dirname == "" { - return "." - } - return dirname -} - // urlJoinPath Join a path to existing URL. func urlJoinPath(url1, url2 string) string { u1 := client.NewURL(url1)