stat: print information about all buckets when only alias are set (#5002)

This commit is contained in:
dorman
2024-08-08 19:04:42 -07:00
committed by GitHub
parent d6886b33d2
commit e7d1e97852
2 changed files with 37 additions and 13 deletions
+30 -8
View File
@@ -19,6 +19,7 @@ package cmd
import (
"context"
"path/filepath"
"strings"
"time"
@@ -46,6 +47,10 @@ var (
Name: "recursive, r",
Usage: "stat all objects recursively",
},
cli.BoolFlag{
Name: "verbose, v",
Usage: "show verbose buckets information",
},
}
)
@@ -71,20 +76,23 @@ EXAMPLES:
1. Stat all contents of mybucket on Amazon S3 cloud storage.
{{.Prompt}} {{.HelpName}} s3/mybucket/
2. Stat all contents of mybucket on Amazon S3 cloud storage on Microsoft Windows.
2. Stat all contents of all buckets on Amazon S3 cloud storage.
{{.Prompt}} {{.HelpName}} s3 --verbose
3. Stat all contents of mybucket on Amazon S3 cloud storage on Microsoft Windows.
{{.Prompt}} {{.HelpName}} s3\mybucket\
3. Stat files recursively on a local filesystem on Microsoft Windows.
4. Stat files recursively on a local filesystem on Microsoft Windows.
{{.Prompt}} {{.HelpName}} --recursive C:\Users\mydocuments\
4. Stat encrypted files on Amazon S3 cloud storage. In case the encryption key contains non-printable character like tab, pass the
5. Stat encrypted files on Amazon S3 cloud storage. In case the encryption key contains non-printable character like tab, pass the
base64 encoded string as key.
{{.Prompt}} {{.HelpName}} --enc-c "s3/personal-document/=MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDA" s3/personal-document/2019-account_report.docx
5. Stat a specific object version.
6. Stat a specific object version.
{{.Prompt}} {{.HelpName}} --version-id "CL3sWgdSN2pNntSf6UnZAuh2kcu8E8si" s3/personal-docs/2018-account_report.docx
6. Stat all objects versions recursively created before 1st January 2020.
7. Stat all objects versions recursively created before 1st January 2020.
{{.Prompt}} {{.HelpName}} --versions --rewind 2020.01.01T00:00 s3/personal-docs/
`,
}
@@ -117,15 +125,29 @@ func parseAndCheckStatSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB
if versionID != "" && (recursive || withVersions || !rewind.IsZero()) {
fatalIf(errInvalidArgument().Trace(args...), "You cannot specify --version-id with either --rewind, --versions or --recursive.")
}
var targetUrls []string
for _, url := range URLs {
_, _, err := url2Stat(ctx, url2StatOptions{urlStr: url, versionID: versionID, fileAttr: false, encKeyDB: encKeyDB, timeRef: rewind, isZip: false, ignoreBucketExistsCheck: false})
if err != nil {
fatalIf(err.Trace(url), "Unable to stat `"+url+"`.")
}
_, path := url2Alias(url)
if path != "" || !cliCtx.Bool("verbose") {
targetUrls = append(targetUrls, url)
continue
}
clnt, err := newClient(url)
fatalIf(err.Trace(args...), "Unable to initialize `"+url+"`.")
buckets, e := clnt.ListBuckets(ctx)
if e != nil || len(buckets) == 0 {
targetUrls = append(targetUrls, url)
continue
}
for _, bucket := range buckets {
targetUrls = append(targetUrls, filepath.Join(url, bucket.BucketName))
}
}
return URLs, recursive, versionID, rewind, withVersions
return targetUrls, recursive, versionID, rewind, withVersions
}
// mainStat - is a handler for mc stat command
+7 -5
View File
@@ -61,7 +61,7 @@ func (stat statMessage) String() (msg string) {
// Format properly for alignment based on maxKey leng
stat.Key = fmt.Sprintf("%-10s: %s", "Name", stat.Key)
msgBuilder.WriteString(console.Colorize("Name", stat.Key) + "\n")
if !stat.Date.IsZero() {
if !stat.Date.IsZero() && !stat.Date.Equal(timeSentinel) {
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Date", stat.Date.Format(printDate)) + "\n")
}
if stat.Type != "folder" {
@@ -79,17 +79,19 @@ func (stat statMessage) String() (msg string) {
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "VersionID", versionIDField) + "\n")
}
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Type", stat.Type) + "\n")
if stat.Expires != nil {
if stat.Expires != nil && !stat.Expires.IsZero() && !stat.Expires.Equal(timeSentinel) {
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Expires", stat.Expires.Format(printDate)) + "\n")
}
if stat.Expiration != nil {
if stat.Expiration != nil && !stat.Expiration.IsZero() && !stat.Expiration.Equal(timeSentinel) {
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s (lifecycle-rule-id: %s) ", "Expiration",
stat.Expiration.Local().Format(printDate), stat.ExpirationRuleID) + "\n")
}
if stat.Restore != nil {
msgBuilder.WriteString(fmt.Sprintf("%-10s:", "Restore") + "\n")
msgBuilder.WriteString(fmt.Sprintf(" %-10s: %s", "ExpiryTime",
stat.Restore.ExpiryTime.Local().Format(printDate)) + "\n")
if !stat.Restore.ExpiryTime.IsZero() && !stat.Restore.ExpiryTime.Equal(timeSentinel) {
msgBuilder.WriteString(fmt.Sprintf(" %-10s: %s", "ExpiryTime",
stat.Restore.ExpiryTime.Local().Format(printDate)) + "\n")
}
msgBuilder.WriteString(fmt.Sprintf(" %-10s: %t", "Ongoing",
stat.Restore.OngoingRestore) + "\n")
}