fix: display objects endpoint with / properly (#3408)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Enable tracing if set.
|
||||
[ -n "$BASH_XTRACEFD" ] && set -ex
|
||||
[ -n "$BASH_XTRACEFD" ] && set -x
|
||||
|
||||
function _init() {
|
||||
## All binaries are static make sure to disable CGO.
|
||||
|
||||
+19
-17
@@ -1416,7 +1416,7 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent,
|
||||
// so we can check if there is such prefix which exists
|
||||
ctnt, err := c.getObjectStat(ctx, bucket, object, minio.StatObjectOptions{ServerSideEncryption: opts.sse, VersionID: opts.versionID})
|
||||
if err == nil {
|
||||
return ctnt, err
|
||||
return ctnt, nil
|
||||
}
|
||||
// Ignore object missing error but return for other errors
|
||||
if !errors.As(err.ToGoError(), &ObjectMissing{}) {
|
||||
@@ -1425,8 +1425,6 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent,
|
||||
}
|
||||
|
||||
nonRecursive := false
|
||||
objectMetadata := &ClientContent{}
|
||||
|
||||
// Prefix to pass to minio-go listing in order to fetch if a prefix exists
|
||||
prefix := strings.TrimRight(object, string(c.targetURL.Separator))
|
||||
|
||||
@@ -1435,15 +1433,7 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent,
|
||||
return nil, probe.NewError(objectStat.Err)
|
||||
}
|
||||
|
||||
if objectStat.Key == prefix {
|
||||
return c.objectInfo2ClientContent(bucket, objectStat), nil
|
||||
}
|
||||
|
||||
if strings.HasSuffix(objectStat.Key, string(c.targetURL.Separator)) {
|
||||
objectMetadata.URL = c.targetURL.Clone()
|
||||
objectMetadata.Type = os.ModeDir
|
||||
return objectMetadata, nil
|
||||
}
|
||||
return c.objectInfo2ClientContent(bucket, objectStat), nil
|
||||
}
|
||||
|
||||
return nil, probe.NewError(ObjectMissing{opts.timeRef})
|
||||
@@ -2001,18 +1991,30 @@ func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInf
|
||||
content.ReplicationStatus = entry.ReplicationStatus
|
||||
for k, v := range entry.UserMetadata {
|
||||
content.UserMetadata[k] = v
|
||||
attr, _ := parseAttribute(content.UserMetadata)
|
||||
}
|
||||
for k := range entry.Metadata {
|
||||
content.Metadata[k] = entry.Metadata.Get(k)
|
||||
}
|
||||
attr, _ := parseAttribute(content.UserMetadata)
|
||||
if len(attr) > 0 {
|
||||
_, mtime, _ := parseAtimeMtime(attr)
|
||||
if !mtime.IsZero() {
|
||||
content.Time = mtime
|
||||
}
|
||||
}
|
||||
for k := range entry.Metadata {
|
||||
content.Metadata[k] = entry.Metadata.Get(k)
|
||||
attr, _ = parseAttribute(content.Metadata)
|
||||
if len(attr) > 0 {
|
||||
_, mtime, _ := parseAtimeMtime(attr)
|
||||
if !mtime.IsZero() {
|
||||
content.Time = mtime
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(entry.Key, string(c.targetURL.Separator)) && entry.Size == 0 && entry.LastModified.IsZero() {
|
||||
|
||||
if strings.HasSuffix(entry.Key, string(c.targetURL.Separator)) {
|
||||
content.Type = os.ModeDir
|
||||
content.Time = time.Now()
|
||||
if content.Time.IsZero() {
|
||||
content.Time = time.Now()
|
||||
}
|
||||
} else {
|
||||
content.Type = os.FileMode(0664)
|
||||
}
|
||||
|
||||
@@ -56,10 +56,6 @@ type contentMessage struct {
|
||||
func (c contentMessage) String() string {
|
||||
message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time.Format(printDate)))
|
||||
message += console.Colorize("Size", fmt.Sprintf("%7s ", strings.Join(strings.Fields(humanize.IBytes(uint64(c.Size))), "")))
|
||||
if c.Filetype == "folder" {
|
||||
return message + console.Colorize("Dir", c.Key)
|
||||
}
|
||||
|
||||
fileDesc := c.Key
|
||||
if c.VersionID != "" {
|
||||
fileDesc += fmt.Sprintf(" (%s, vid=%s", c.VersionOrd, c.VersionID)
|
||||
@@ -69,7 +65,11 @@ func (c contentMessage) String() string {
|
||||
fileDesc += ")"
|
||||
}
|
||||
|
||||
message += console.Colorize("file", fileDesc)
|
||||
if c.Filetype == "folder" {
|
||||
message += console.Colorize("Dir", fileDesc)
|
||||
} else {
|
||||
message += console.Colorize("File", fileDesc)
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
|
||||
+8
-5
@@ -19,6 +19,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -937,16 +938,18 @@ func mainMirror(cliCtx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
default:
|
||||
if errorDetected := runMirror(ctx, cancelMirror, srcURL, tgtURL, cliCtx, encKeyDB); errorDetected {
|
||||
if cliCtx.Bool("multi-master") || cliCtx.Bool("active-active") {
|
||||
time.Sleep(2 * time.Second)
|
||||
continue
|
||||
}
|
||||
errorDetected := runMirror(ctx, cancelMirror, srcURL, tgtURL, cliCtx, encKeyDB)
|
||||
if cliCtx.Bool("multi-master") || cliCtx.Bool("active-active") {
|
||||
time.Sleep(time.Duration(r.Float64() * float64(2*time.Second)))
|
||||
continue
|
||||
}
|
||||
if errorDetected {
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
return nil
|
||||
|
||||
+5
-8
@@ -161,17 +161,14 @@ func mainStat(cliCtx *cli.Context) error {
|
||||
|
||||
var cErr error
|
||||
for _, targetURL := range args {
|
||||
stats, err := statURL(ctx, targetURL, versionID, rewind, withVersions, false, isRecursive, encKeyDB)
|
||||
contents, err := statURL(ctx, targetURL, versionID, rewind, withVersions, false, isRecursive, encKeyDB)
|
||||
if err != nil {
|
||||
fatalIf(err, "Unable to stat `"+targetURL+"`.")
|
||||
}
|
||||
for _, stat := range stats {
|
||||
st := parseStat(stat)
|
||||
if !globalJSON {
|
||||
printStat(st)
|
||||
} else {
|
||||
console.Println(st.JSON())
|
||||
}
|
||||
for _, content := range contents {
|
||||
stat := parseStat(content)
|
||||
stat.singleObject = len(contents) == 1
|
||||
printMsg(stat)
|
||||
}
|
||||
}
|
||||
return cErr
|
||||
|
||||
+33
-33
@@ -44,77 +44,77 @@ type statMessage struct {
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
VersionID string `json:"versionID,omitempty"`
|
||||
DeleteMarker bool `json:"deleteMarker,omitempty"`
|
||||
singleObject bool
|
||||
}
|
||||
|
||||
// String colorized string message.
|
||||
func printStat(stat statMessage) {
|
||||
// Format properly for alignment based on maxKey length
|
||||
func (stat statMessage) String() (msg string) {
|
||||
var msgBuilder strings.Builder
|
||||
// Format properly for alignment based on maxKey leng
|
||||
stat.Key = fmt.Sprintf("%-10s: %s", "Name", stat.Key)
|
||||
console.Println(console.Colorize("Name", stat.Key))
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "Date", stat.Date.Format(printDate)))
|
||||
console.Println(fmt.Sprintf("%-10s: %-6s ", "Size", humanize.IBytes(uint64(stat.Size))))
|
||||
msgBuilder.WriteString(console.Colorize("Name", stat.Key) + "\n")
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Date", stat.Date.Format(printDate)) + "\n")
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %-6s ", "Size", humanize.IBytes(uint64(stat.Size))) + "\n")
|
||||
if stat.ETag != "" {
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "ETag", stat.ETag))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "ETag", stat.ETag) + "\n")
|
||||
}
|
||||
if stat.VersionID != "" {
|
||||
versionIDField := stat.VersionID
|
||||
if stat.DeleteMarker {
|
||||
versionIDField += " (delete-marker)"
|
||||
}
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "VersionID", versionIDField))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "VersionID", versionIDField) + "\n")
|
||||
}
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "Type", stat.Type))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Type", stat.Type) + "\n")
|
||||
if !stat.Expires.IsZero() {
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "Expires", stat.Expires.Format(printDate)))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Expires", stat.Expires.Format(printDate)) + "\n")
|
||||
}
|
||||
if !stat.Expiration.IsZero() {
|
||||
console.Println(fmt.Sprintf("%-10s: %s (lifecycle-rule-id: %s) ", "Expiration", stat.Expiration.Local().Format(printDate), stat.ExpirationRuleID))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s (lifecycle-rule-id: %s) ", "Expiration",
|
||||
stat.Expiration.Local().Format(printDate), stat.ExpirationRuleID) + "\n")
|
||||
}
|
||||
var maxKey = 0
|
||||
var maxKeyMetadata = 0
|
||||
var maxKeyEncrypted = 0
|
||||
for k := range stat.Metadata {
|
||||
// Skip encryption headers, we print them later.
|
||||
if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
if len(k) > maxKeyMetadata {
|
||||
maxKeyMetadata = len(k)
|
||||
}
|
||||
} else if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
if len(k) > maxKeyEncrypted {
|
||||
maxKeyEncrypted = len(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if maxKey > 0 {
|
||||
console.Println(fmt.Sprintf("%-10s:", "Metadata"))
|
||||
if maxKeyMetadata > 0 {
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s:", "Metadata") + "\n")
|
||||
for k, v := range stat.Metadata {
|
||||
// Skip encryption headers, we print them later.
|
||||
if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
msgBuilder.WriteString(fmt.Sprintf(" %-*.*s: %s ", maxKeyMetadata, maxKeyMetadata, k, v) + "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxKey = 0
|
||||
for k := range stat.Metadata {
|
||||
if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if maxKey > 0 {
|
||||
console.Println(fmt.Sprintf("%-10s:", "Encrypted"))
|
||||
if maxKeyEncrypted > 0 {
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s:", "Encrypted") + "\n")
|
||||
for k, v := range stat.Metadata {
|
||||
if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
msgBuilder.WriteString(fmt.Sprintf(" %-*.*s: %s ", maxKeyEncrypted, maxKeyEncrypted, k, v) + "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
if stat.ReplicationStatus != "" {
|
||||
console.Println(fmt.Sprintf("%-10s: %s ", "Replication Status", stat.ReplicationStatus))
|
||||
msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Replication Status", stat.ReplicationStatus))
|
||||
}
|
||||
console.Println()
|
||||
|
||||
return msgBuilder.String()
|
||||
}
|
||||
|
||||
// JSON jsonified content message.
|
||||
func (c statMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||
func (stat statMessage) JSON() string {
|
||||
stat.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(stat, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
+6
-13
@@ -31,7 +31,6 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
@@ -332,17 +331,14 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe
|
||||
if e != nil {
|
||||
return atime, mtime, probe.NewError(e)
|
||||
}
|
||||
at := syscall.Timespec{
|
||||
Sec: atim,
|
||||
}
|
||||
var atimnsec int64
|
||||
if len(vals) == 2 {
|
||||
atimnsec, e := strconv.ParseInt(vals[1], 10, 64)
|
||||
atimnsec, e = strconv.ParseInt(vals[1], 10, 64)
|
||||
if e != nil {
|
||||
return atime, mtime, probe.NewError(e)
|
||||
}
|
||||
at.Nsec = atimnsec
|
||||
}
|
||||
atime = time.Unix(at.Unix())
|
||||
atime = time.Unix(int64(atim), int64(atimnsec))
|
||||
}
|
||||
|
||||
if val, ok := attr["mtime"]; ok {
|
||||
@@ -351,17 +347,14 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe
|
||||
if e != nil {
|
||||
return atime, mtime, probe.NewError(e)
|
||||
}
|
||||
mt := syscall.Timespec{
|
||||
Sec: mtim,
|
||||
}
|
||||
var mtimnsec int64
|
||||
if len(vals) == 2 {
|
||||
mtimnsec, e := strconv.ParseInt(vals[1], 10, 64)
|
||||
mtimnsec, e = strconv.ParseInt(vals[1], 10, 64)
|
||||
if e != nil {
|
||||
return atime, mtime, probe.NewError(e)
|
||||
}
|
||||
mt.Nsec = mtimnsec
|
||||
}
|
||||
mtime = time.Unix(mt.Unix())
|
||||
mtime = time.Unix(int64(mtim), int64(mtimnsec))
|
||||
}
|
||||
return atime, mtime, nil
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func GetFileSystemAttrs(file string) (string, error) {
|
||||
|
||||
var fileAttr strings.Builder
|
||||
fileAttr.WriteString("atime:")
|
||||
fileAttr.WriteString(strconv.FormatInt(st.Atim.Sec, 10) + "#" + strconv.FormatInt(st.Atim.Nsec, 10))
|
||||
fileAttr.WriteString(strconv.FormatInt(int64(st.Atim.Sec), 10) + "#" + strconv.FormatInt(int64(st.Atim.Nsec), 10))
|
||||
fileAttr.WriteString("/gid:")
|
||||
fileAttr.WriteString(strconv.Itoa(int(st.Gid)))
|
||||
|
||||
@@ -51,7 +51,7 @@ func GetFileSystemAttrs(file string) (string, error) {
|
||||
fileAttr.WriteString("/mode:")
|
||||
fileAttr.WriteString(strconv.Itoa(int(st.Mode)))
|
||||
fileAttr.WriteString("/mtime:")
|
||||
fileAttr.WriteString(strconv.FormatInt(st.Mtim.Sec, 10) + "#" + strconv.FormatInt(st.Mtim.Nsec, 10))
|
||||
fileAttr.WriteString(strconv.FormatInt(int64(st.Mtim.Sec), 10) + "#" + strconv.FormatInt(int64(st.Mtim.Nsec), 10))
|
||||
fileAttr.WriteString("/uid:")
|
||||
fileAttr.WriteString(strconv.Itoa(int(st.Uid)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user