diff --git a/cmd_test.go b/cmd_test.go index c50b0173..7b73683d 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -96,7 +96,7 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) { wg := &sync.WaitGroup{} - data1 := "hello1" + data1 := "hello world 1" binarySum1 := md5.Sum([]byte(data1)) etag1 := base64.StdEncoding.EncodeToString(binarySum1[:]) dataLen1 := int64(len(data1)) @@ -500,12 +500,13 @@ func (s *CmdTestSuite) TestCatCmdObject(c *C) { targetReader, targetWriter := io.Pipe() var resultBuffer bytes.Buffer wg := &sync.WaitGroup{} - wg.Add(2) + wg.Add(1) go func() { io.Copy(sourceWriter, bytes.NewBufferString(data1)) sourceWriter.Close() wg.Done() }() + wg.Add(1) go func() { io.Copy(&resultBuffer, targetReader) wg.Done() @@ -518,6 +519,8 @@ func (s *CmdTestSuite) TestCatCmdObject(c *C) { c.Assert(msg, Equals, "") c.Assert(err, IsNil) + // without this there will be data races + wg.Wait() c.Assert(data1, Equals, resultBuffer.String()) methods.AssertExpectations(c) @@ -550,12 +553,13 @@ func (s *CmdTestSuite) TestCatCmdFile(c *C) { targetReader, targetWriter := io.Pipe() var resultBuffer bytes.Buffer wg := &sync.WaitGroup{} - wg.Add(2) + wg.Add(1) go func() { io.Copy(sourceWriter, bytes.NewBufferString(data1)) sourceWriter.Close() wg.Done() }() + wg.Add(1) go func() { io.Copy(&resultBuffer, targetReader) wg.Done() @@ -569,6 +573,8 @@ func (s *CmdTestSuite) TestCatCmdFile(c *C) { c.Assert(msg, Equals, "") c.Assert(err, IsNil) + // with this there will be data races + wg.Wait() c.Assert(data1, Equals, resultBuffer.String()) methods.AssertExpectations(c) diff --git a/copy.go b/copy.go index 1c3ae345..50d7ead9 100644 --- a/copy.go +++ b/copy.go @@ -60,7 +60,18 @@ func doCopySingleSource(methods clientMethods, sourceURL, targetURL string, sour if err != nil { return iodine.New(err, nil) } - return doCopy(methods, reader, md5hex, length, targetURL, targetConfig) + // check if its a directory, construct the new TargetURL, if not fallback + newTargetURL, err := getNewTargetURL(targetURL, sourceURL) + switch iodine.ToError(err).(type) { + case errIsNotDIR: + return doCopy(methods, reader, md5hex, length, targetURL, targetConfig) + case errIsNotBucket: + return doCopy(methods, reader, md5hex, length, targetURL, targetConfig) + case nil: + return doCopy(methods, reader, md5hex, length, newTargetURL, targetConfig) + default: + return iodine.New(err, nil) + } } func doCopySingleSourceRecursive(methods clientMethods, sourceURL, targetURL string, sourceConfig, targetConfig *hostConfig) error {