Support create Dir and listBucket add Dir info

(cherry picked from commit eecd8095d80ccb6922ec87e7e214b5880a047899)
This commit is contained in:
David Hao
2024-07-15 22:08:12 +08:00
committed by itsHenry
parent 390ec18aac
commit 8a3e25d461
2 changed files with 29 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"math"
@@ -246,6 +247,31 @@ func (g *GoFakeS3) listBucket(bucketName string, w http.ResponseWriter, r *http.
ctx := r.Context()
objects, err := g.storage.ListBucket(ctx, bucketName, &prefix, page)
log.Debugf("objects.Contents: %v, prefix: %v", objects.Contents, prefix)
hasPrefixSelf := false
if objects.Contents != nil {
for _, v := range objects.Contents {
if v.Key == prefix.Prefix {
hasPrefixSelf = true
break
}
}
}
if !hasPrefixSelf {
log.Infof("objects.Contents not has prefix self, need to add it.")
objects.Contents = append(objects.Contents, &Content{
Key: prefix.Prefix,
LastModified: NewContentTime(time.Time{}),
ETag: "",
Size: 0,
StorageClass: StorageStandard,
Owner: nil,
})
}
log.Debugf("objects.Contents: %v", objects.Contents)
if err != nil {
if err == ErrInternalPageNotImplemented && !g.failOnUnimplementedPage {
// We have observed (though not yet confirmed) that simple clients

View File

@@ -55,6 +55,9 @@ func (g *GoFakeS3) routeBase(w http.ResponseWriter, r *http.Request) {
err = g.routeVersion(bucket, object, VersionID(versionID), w, r)
} else if bucket != "" && object != "" {
if strings.HasSuffix(r.URL.Path, "/") {
object = object + "/"
}
err = g.routeObject(bucket, object, w, r)
} else if bucket != "" {