fix listObjectsV2 response format

fix https://github.com/chrislusf/seaweedfs/issues/1426 issue 1
This commit is contained in:
Chris Lu 2020-08-19 12:07:43 -07:00
parent e455eb8891
commit c45ba5d7d4
3 changed files with 27 additions and 7 deletions

View file

@ -61,7 +61,7 @@ func TestCreateBucket(t *testing.T) {
} }
func TestListBuckets(t *testing.T) { func TestPutObject(t *testing.T) {
input := &s3.PutObjectInput{ input := &s3.PutObjectInput{
ACL: aws.String("authenticated-read"), ACL: aws.String("authenticated-read"),
@ -89,7 +89,7 @@ func TestListBuckets(t *testing.T) {
} }
func TestPutObject(t *testing.T) { func TestListBucket(t *testing.T) {
result, err := svc.ListBuckets(nil) result, err := svc.ListBuckets(nil)
if err != nil { if err != nil {
@ -105,6 +105,23 @@ func TestPutObject(t *testing.T) {
} }
func TestListObjectV2(t *testing.T) {
listObj, err := svc.ListObjectsV2(&s3.ListObjectsV2Input{
Bucket: aws.String(Bucket),
Prefix: aws.String("foo"),
Delimiter: aws.String("/"),
})
if err != nil {
exitErrorf("Unable to list objects, %v", err)
}
for _, content := range listObj.Contents {
fmt.Println(aws.StringValue(content.Key))
}
fmt.Printf("list: %s\n", listObj)
}
func exitErrorf(msg string, args ...interface{}) { func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...) fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1) os.Exit(1)

View file

@ -13,3 +13,7 @@ clean:
debug_mount: debug_mount:
go build -gcflags="all=-N -l" go build -gcflags="all=-N -l"
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec weed -- mount -dir=~/tmp/mm dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec weed -- mount -dir=~/tmp/mm
debug_server:
go build -gcflags="all=-N -l"
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec weed -- server -dir=/Volumes/mobile_disk/99 -filer -volume.port=8343 -s3 -volume.max=0

View file

@ -112,12 +112,12 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m
if strings.HasPrefix(reqDir, "/") { if strings.HasPrefix(reqDir, "/") {
reqDir = reqDir[1:] reqDir = reqDir[1:]
} }
bucketPrefix := fmt.Sprintf("%s/%s/", s3a.option.BucketsPath, bucket)
reqDir = fmt.Sprintf("%s%s", bucketPrefix, reqDir)
if strings.HasSuffix(reqDir, "/") { if strings.HasSuffix(reqDir, "/") {
// remove trailing "/" // remove trailing "/"
reqDir = reqDir[:len(reqDir)-1] reqDir = reqDir[:len(reqDir)-1]
} }
bucketPrefix := fmt.Sprintf("%s/%s/", s3a.option.BucketsPath, bucket)
reqDir = fmt.Sprintf("%s%s", bucketPrefix, reqDir)
var contents []ListEntry var contents []ListEntry
var commonPrefixes []PrefixEntry var commonPrefixes []PrefixEntry
@ -131,14 +131,13 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m
_, isTruncated, nextMarker, doErr = s3a.doListFilerEntries(client, reqDir, prefix, maxKeys, marker, delimiter, func(dir string, entry *filer_pb.Entry) { _, isTruncated, nextMarker, doErr = s3a.doListFilerEntries(client, reqDir, prefix, maxKeys, marker, delimiter, func(dir string, entry *filer_pb.Entry) {
if entry.IsDirectory { if entry.IsDirectory {
if delimiter == "/" { if delimiter == "/" {
prefix = fmt.Sprintf("%s%s/", dir, entry.Name)
commonPrefixes = append(commonPrefixes, PrefixEntry{ commonPrefixes = append(commonPrefixes, PrefixEntry{
Prefix: prefix[len(bucketPrefix):], Prefix: fmt.Sprintf("%s/%s/", dir, entry.Name)[len(bucketPrefix):],
}) })
} }
} else { } else {
contents = append(contents, ListEntry{ contents = append(contents, ListEntry{
Key: fmt.Sprintf("%s%s", dir[len(bucketPrefix):], entry.Name), Key: fmt.Sprintf("%s/%s", dir, entry.Name)[len(bucketPrefix):],
LastModified: time.Unix(entry.Attributes.Mtime, 0).UTC(), LastModified: time.Unix(entry.Attributes.Mtime, 0).UTC(),
ETag: "\"" + filer2.ETag(entry) + "\"", ETag: "\"" + filer2.ETag(entry) + "\"",
Size: int64(filer2.FileSize(entry)), Size: int64(filer2.FileSize(entry)),