From 4ab7f30f996017dae684e91d629c5f498e3a9147 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 29 Jun 2018 16:56:02 -0700 Subject: [PATCH] Handle directories properly in cp and mirror (#2478) Fixes #2477 --- .travis.yml | 10 ---------- cmd/client-s3.go | 32 +++++++++++++++----------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79115cad..7e7ae5b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,16 +13,6 @@ matrix: - diff -au <(gofmt -d *.go) <(printf "") - diff -au <(gofmt -d cmd) <(printf "") - diff -au <(gofmt -d pkg) <(printf "") - - os: linux-ppc64le - env: - - ARCH=ppc64le - go: 1.10.1 - script: - - make test - - make coverage - - diff -au <(gofmt -d *.go) <(printf "") - - diff -au <(gofmt -d cmd) <(printf "") - - diff -au <(gofmt -d pkg) <(printf "") after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 9cc1a1f0..1298b227 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -989,7 +989,21 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta bool, sseKey string) (*clientC if objectStat.Err != nil { return nil, probe.NewError(objectStat.Err) } - if objectStat.Key == object { + if strings.HasSuffix(objectStat.Key, string(c.targetURL.Separator)) { + objectMetadata.URL = *c.targetURL + objectMetadata.Type = os.ModeDir + + if isFetchMeta { + stat, err := c.getObjectStat(bucket, object, opts) + if err != nil { + return nil, err + } + objectMetadata.ETag = stat.ETag + objectMetadata.Metadata = stat.Metadata + objectMetadata.EncryptionHeaders = stat.EncryptionHeaders + } + return objectMetadata, nil + } else if objectStat.Key == object { objectMetadata.URL = *c.targetURL objectMetadata.Time = objectStat.LastModified objectMetadata.Size = objectStat.Size @@ -1007,22 +1021,6 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta bool, sseKey string) (*clientC } return objectMetadata, nil } - - if strings.HasSuffix(objectStat.Key, string(c.targetURL.Separator)) { - objectMetadata.URL = *c.targetURL - objectMetadata.Type = os.ModeDir - - if isFetchMeta { - stat, err := c.getObjectStat(bucket, object, opts) - if err != nil { - return nil, err - } - objectMetadata.ETag = stat.ETag - objectMetadata.Metadata = stat.Metadata - objectMetadata.EncryptionHeaders = stat.EncryptionHeaders - } - return objectMetadata, nil - } } return c.getObjectStat(bucket, object, opts) }