Fix an error in recursive behavior for filesystem
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user