From f10349191228cb945cabfe049b601ab3e251b55c Mon Sep 17 00:00:00 2001 From: chrislu Date: Fri, 21 Jan 2022 00:26:49 -0800 Subject: [PATCH] s3: list bucket size from weed shell --- weed/shell/command_s3_bucket_list.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/weed/shell/command_s3_bucket_list.go b/weed/shell/command_s3_bucket_list.go index a344a79a4..540365af5 100644 --- a/weed/shell/command_s3_bucket_list.go +++ b/weed/shell/command_s3_bucket_list.go @@ -34,6 +34,14 @@ func (c *commandS3BucketList) Do(args []string, commandEnv *CommandEnv, writer i return nil } + // collect collection information + topologyInfo, _, err := collectTopologyInfo(commandEnv) + if err != nil { + return err + } + collectionInfos := make(map[string]*CollectionInfo) + collectCollectionInfo(topologyInfo, collectionInfos) + _, parseErr := commandEnv.parseUrl(findInputDirectory(bucketCommand.Args())) if parseErr != nil { return parseErr @@ -49,11 +57,13 @@ func (c *commandS3BucketList) Do(args []string, commandEnv *CommandEnv, writer i if !entry.IsDirectory { return nil } - if entry.Attributes.Replication == "" || entry.Attributes.Replication == "000" { - fmt.Fprintf(writer, " %s\n", entry.Name) - } else { - fmt.Fprintf(writer, " %s\t\t\treplication: %s\n", entry.Name, entry.Attributes.Replication) + collection := entry.Name + var collectionSize, fileCount uint64 + if collectionInfo, found := collectionInfos[collection]; found { + collectionSize = collectionInfo.Size + fileCount = collectionInfo.FileCount - collectionInfo.DeleteCount } + fmt.Fprintf(writer, " %s\tsize:%d bytes\tfile:%d\treplication: %s\n", entry.Name, collectionSize, fileCount, entry.Attributes.Replication) return nil }, "", false, math.MaxUint32) if err != nil {