From 26c7c3e500e2cc24a51f161e4c15ebb513e70fff Mon Sep 17 00:00:00 2001 From: poornas Date: Fri, 13 Oct 2017 18:23:13 -0700 Subject: [PATCH] ls: show ETag in json formatted output (#2285) --- cmd/client-s3.go | 6 ++++++ cmd/client.go | 1 + cmd/ls.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 0c70330f..e00335c4 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -879,6 +879,7 @@ func (c *s3Client) Stat(isIncomplete bool) (*clientContent, *probe.Error) { objectMetadata.URL = *c.targetURL objectMetadata.Time = objectStat.LastModified objectMetadata.Size = objectStat.Size + objectMetadata.ETag = objectStat.ETag objectMetadata.Type = os.FileMode(0664) objectMetadata.Metadata = map[string][]string{} return objectMetadata, nil @@ -915,6 +916,7 @@ func (c *s3Client) Stat(isIncomplete bool) (*clientContent, *probe.Error) { objectMetadata.URL = *c.targetURL objectMetadata.Time = objectStat.LastModified objectMetadata.Size = objectStat.Size + objectMetadata.ETag = objectStat.ETag objectMetadata.Type = os.FileMode(0664) metadata := objectStat.Metadata @@ -1252,6 +1254,7 @@ func (c *s3Client) objectInfo2ClientContent(entry minio.ObjectInfo) clientConten url.Path = c.joinPath(bucket, entry.Key) content.URL = url content.Size = entry.Size + content.ETag = entry.ETag content.Time = entry.LastModified if strings.HasSuffix(entry.Key, "/") && entry.Size == 0 && entry.LastModified.IsZero() { @@ -1429,6 +1432,7 @@ func (c *s3Client) listInRoutine(contentCh chan *clientContent) { default: content.URL = url content.Size = object.Size + content.ETag = object.ETag content.Time = object.LastModified content.Type = os.FileMode(0664) } @@ -1484,6 +1488,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan *clientContent) { objectURL.Path = c.joinPath(bucket.Name, object.Key) content.URL = objectURL content.Size = object.Size + content.ETag = object.ETag content.Time = object.LastModified content.Type = os.FileMode(0664) contentCh <- content @@ -1508,6 +1513,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan *clientContent) { url.Path = c.joinPath(b, object.Key) content.URL = url content.Size = object.Size + content.ETag = object.ETag content.Time = object.LastModified content.Type = os.FileMode(0664) contentCh <- content diff --git a/cmd/client.go b/cmd/client.go index e406dc0c..db7f9e77 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -80,6 +80,7 @@ type clientContent struct { Time time.Time Size int64 Type os.FileMode + ETag string Metadata map[string][]string Err *probe.Error } diff --git a/cmd/ls.go b/cmd/ls.go index 04e0ad04..778b1534 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -41,6 +41,7 @@ type contentMessage struct { Time time.Time `json:"lastModified"` Size int64 `json:"size"` Key string `json:"key"` + ETag string `json:"etag"` } // String colorized string message. @@ -79,6 +80,9 @@ func parseContent(c *clientContent) contentMessage { }() content.Size = c.Size + md5sum := strings.TrimPrefix(c.ETag, "\"") + md5sum = strings.TrimSuffix(md5sum, "\"") + content.ETag = md5sum // Convert OS Type to match console file printing style. content.Key = func() string { switch {