diff --git a/cp-url.go b/cp-url.go index 1c9e43f7..66722d8f 100644 --- a/cp-url.go +++ b/cp-url.go @@ -124,7 +124,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs { return &cpURLs{Error: iodine.New(err, nil)} } - // Source exist? + // Source exists? sourceContent, err := sourceClient.Stat() if err != nil { // Source does not exist or insufficient privileges. @@ -134,12 +134,12 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs { // Source is not a regular file return &cpURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)} } + targetClient, err := target2Client(targetURL) if err != nil { return &cpURLs{Error: iodine.New(err, nil)} } - - // Target exist? + // Target exists? targetContent, err := targetClient.Stat() if err == nil { // Target exists. if !targetContent.Type.IsRegular() { // Target is not a regular file @@ -148,6 +148,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs { } // All OK.. We can proceed. Type A + sourceContent.Name = sourceURL return &cpURLs{SourceContent: sourceContent, TargetContent: &client.Content{Name: targetURL}} } diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 45169b61..5ce8c21b 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -159,6 +159,16 @@ func (c *s3Client) SetBucketACL(acl string) error { func (c *s3Client) Stat() (*client.Content, error) { objectMetadata := new(client.Content) bucket, object := c.url2BucketAndObject() + switch { + // valid case for s3:... + case bucket == "" && object == "": + for bucket := range c.api.ListBuckets() { + if bucket.Err != nil { + return nil, iodine.New(bucket.Err, nil) + } + return &client.Content{Type: os.ModeDir}, nil + } + } if object != "" { metadata, err := c.api.StatObject(bucket, object) if err != nil { @@ -336,8 +346,18 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel } content := new(client.Content) normalizedKey := object.Stat.Key - if strings.HasSuffix(o, delimiter) { - normalizedKey = strings.TrimPrefix(object.Stat.Key, o) + switch { + case o == "": + // if no prefix provided and also URL is not delimited then we add bucket back into object name + if strings.LastIndex(c.hostURL.Path, string(c.hostURL.Separator)) == 0 { + if c.hostURL.String()[:strings.LastIndex(c.hostURL.String(), string(c.hostURL.Separator))+1] != b { + normalizedKey = filepath.Join(b, object.Stat.Key) + } + } + default: + if strings.HasSuffix(o, delimiter) { + normalizedKey = strings.TrimPrefix(object.Stat.Key, o) + } } content.Name = normalizedKey content.Size = object.Stat.Size