Reply messages from doCopyCmdRecursive() and do not exit on errors during doCopyCmd()
This commit is contained in:
+15
-9
@@ -17,16 +17,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/minio-io/mc/pkg/console"
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
"github.com/minio-io/minio/pkg/utils/log"
|
||||
)
|
||||
|
||||
const (
|
||||
pathSeparator = "/"
|
||||
|
||||
// pathSeparatorWindows = "\\"
|
||||
)
|
||||
|
||||
// doCopyCmdRecursive - copy bucket to bucket
|
||||
@@ -34,24 +34,30 @@ func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*ho
|
||||
for sourceURL, sourceConfig := range sourceURLConfigMap {
|
||||
// get source list
|
||||
clnt, err := manager.getNewClient(sourceURL, sourceConfig, false)
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
if err != nil {
|
||||
return fmt.Sprintf("instantiating a new client for URL [%s]", sourceURL), iodine.New(err, nil)
|
||||
}
|
||||
items, err := clnt.List()
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
if err != nil {
|
||||
return fmt.Sprintf("listing objects failed for URL [%s]", sourceURL), iodine.New(err, nil)
|
||||
}
|
||||
for _, item := range items {
|
||||
// get source url
|
||||
// populate source urls
|
||||
sourceURLs := make(map[string]*hostConfig)
|
||||
sourceObjectURL := strings.TrimSuffix(sourceURL, pathSeparator) + pathSeparator + item.Name
|
||||
sourceURLs[sourceObjectURL] = sourceConfig
|
||||
// get target urls
|
||||
// populate target urls
|
||||
targetURLs := make(map[string]*hostConfig)
|
||||
for targetURL, targetConfig := range targetURLConfigMap {
|
||||
targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + item.Name
|
||||
targetURLs[targetObjectURL] = targetConfig
|
||||
}
|
||||
humanReadable, err := doCopyCmd(manager, sourceURLs, targetURLs)
|
||||
// TODO work out how to report errors
|
||||
log.Debug.Println(humanReadable)
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
if err != nil {
|
||||
err := iodine.New(err, nil)
|
||||
log.Debug.Println(err)
|
||||
console.Errorf("%s with following reason: [%s]\n", humanReadable, iodine.ToError(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
|
||||
+4
-2
@@ -148,9 +148,11 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) {
|
||||
|
||||
manager.On("getNewClient", sourceURL, sourceConfig, false).Return(cl1, nil).Once()
|
||||
cl1.On("List").Return(items, nil).Once()
|
||||
manager.On("getSourceReader", sourceURL+"hello1", sourceConfig).Return(ioutil.NopCloser(bytes.NewBufferString(data1)), dataLen1, etag1, nil).Once()
|
||||
sourceReader1 := ioutil.NopCloser(bytes.NewBufferString(data1))
|
||||
sourceReader2 := ioutil.NopCloser(bytes.NewBufferString(data2))
|
||||
manager.On("getSourceReader", sourceURL+"hello1", sourceConfig).Return(sourceReader1, dataLen1, etag1, nil).Once()
|
||||
manager.On("getTargetWriter", targetURL+"hello1", targetConfig, etag1, dataLen1).Return(writer1, nil).Once()
|
||||
manager.On("getSourceReader", sourceURL+"hello2", sourceConfig).Return(ioutil.NopCloser(bytes.NewBufferString(data2)), dataLen2, etag2, nil).Once()
|
||||
manager.On("getSourceReader", sourceURL+"hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once()
|
||||
manager.On("getTargetWriter", targetURL+"hello2", targetConfig, etag2, dataLen2).Return(writer2, nil).Once()
|
||||
|
||||
msg, err := doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap)
|
||||
|
||||
Reference in New Issue
Block a user