From 7b55d29a80ebe2541c35ec92f29ef3db324111a8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 26 Apr 2015 17:50:03 -0700 Subject: [PATCH] Fix an error in recursive behavior for filesystem --- copy.go | 10 ++-------- url.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/copy.go b/copy.go index 8ec2c176..6124d326 100644 --- a/copy.go +++ b/copy.go @@ -2,7 +2,6 @@ package main import ( "io" - "strings" "github.com/cheggaaa/pb" "github.com/minio-io/mc/pkg/console" @@ -59,13 +58,8 @@ func doCopySingleSourceRecursive(methods clientMethods, sourceURL, targetURL str if itemCh.Err != nil { continue } - sourceURL = strings.TrimSuffix(sourceURL, getObjectKey(sourceURL)) - newSourceURL := strings.TrimSuffix(sourceURL, pathSeparator) + pathSeparator + itemCh.Item.Name - newTargetURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + itemCh.Item.Name - if err := doCopySingleSource(methods, newSourceURL, newTargetURL, sourceConfig, targetConfig); err != nil { - console.Errorf("Failed to copy sourceURL: [%s] to targetURL: [%s] with reason: [%s]\n", - newSourceURL, newTargetURL, iodine.ToError(err)) - } + newSourceURL, newTargetURL := getNewURLRecursive(sourceURL, targetURL, itemCh.Item.Name) + doCopySingleSource(methods, newSourceURL, newTargetURL, sourceConfig, targetConfig) } return nil } diff --git a/url.go b/url.go index 081fe7b4..f0c9ee01 100644 --- a/url.go +++ b/url.go @@ -44,6 +44,20 @@ func getObjectKey(sourceURL string) (objectName string) { return "" } +func getNewURLRecursive(sourceURL, targetURL, url string) (newSourceURL, newTargetURL string) { + switch client.GetType(sourceURL) { + case client.Object: + sourceURL = strings.TrimSuffix(sourceURL, getObjectKey(sourceURL)) + newSourceURL = strings.TrimSuffix(sourceURL, pathSeparator) + pathSeparator + url + newTargetURL = strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + url + case client.Filesystem: + newSourceURL = url + prefix := strings.TrimSuffix(sourceURL, pathSeparator) + pathSeparator + newTargetURL = strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + strings.TrimPrefix(url, prefix) + } + return newSourceURL, newTargetURL +} + func getNewTargetURL(targetURL string, sourceURL string) (newTargetURL string, err error) { switch client.GetType(targetURL) { case client.Object: