Fix an error in recursive behavior for filesystem

This commit is contained in:
Harshavardhana
2015-04-26 17:52:19 -07:00
parent b366d55f35
commit 7b55d29a80
2 changed files with 16 additions and 8 deletions
+2 -8
View File
@@ -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
}
+14
View File
@@ -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: