From b10f709c0918ff4f3208c9e7bcc7d589d0f8017d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 16 Nov 2015 10:08:18 -0800 Subject: [PATCH] cp: Fix a crash in cp - fixes #1336 --- cp-url.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cp-url.go b/cp-url.go index e018359a..a2774dbc 100644 --- a/cp-url.go +++ b/cp-url.go @@ -292,8 +292,11 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { // All OK.. We can proceed. Type B: source is a file, target is a folder and exists. srcURL := sourceClient.GetURL() newSourceURL := sourceContent.Content.URL - newSourceSuffix := strings.TrimPrefix(newSourceURL.Path, - srcURL.Path[:strings.LastIndex(srcURL.Path, string(srcURL.Separator))]) + pathSeparatorIndex := strings.LastIndex(srcURL.Path, string(srcURL.Separator)) + newSourceSuffix := newSourceURL.Path + if pathSeparatorIndex > 1 { + newSourceSuffix = strings.TrimPrefix(newSourceURL.Path, srcURL.Path[:pathSeparatorIndex]) + } newTargetURL := urlJoinPath(targetURL, newSourceSuffix) copyURLsCh <- prepareCopyURLsTypeA(sourceContent.Content.URL.String(), newTargetURL) }