From c45ba5d7d4e7bdd21dd0868e6336d088b6483560 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 19 Aug 2020 12:07:43 -0700 Subject: [PATCH] fix listObjectsV2 response format fix https://github.com/chrislusf/seaweedfs/issues/1426 issue 1 --- test/s3/basic/basic_test.go | 21 +++++++++++++++++++-- weed/Makefile | 4 ++++ weed/s3api/s3api_objects_list_handlers.go | 9 ++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/test/s3/basic/basic_test.go b/test/s3/basic/basic_test.go index 1f9e74fc1..653fa1237 100644 --- a/test/s3/basic/basic_test.go +++ b/test/s3/basic/basic_test.go @@ -61,7 +61,7 @@ func TestCreateBucket(t *testing.T) { } -func TestListBuckets(t *testing.T) { +func TestPutObject(t *testing.T) { input := &s3.PutObjectInput{ 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) 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{}) { fmt.Fprintf(os.Stderr, msg+"\n", args...) os.Exit(1) diff --git a/weed/Makefile b/weed/Makefile index 896067df0..ec95aeacb 100644 --- a/weed/Makefile +++ b/weed/Makefile @@ -13,3 +13,7 @@ clean: debug_mount: go build -gcflags="all=-N -l" 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 diff --git a/weed/s3api/s3api_objects_list_handlers.go b/weed/s3api/s3api_objects_list_handlers.go index 46d5b90c7..3354dd2b3 100644 --- a/weed/s3api/s3api_objects_list_handlers.go +++ b/weed/s3api/s3api_objects_list_handlers.go @@ -112,12 +112,12 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m if strings.HasPrefix(reqDir, "/") { reqDir = reqDir[1:] } + bucketPrefix := fmt.Sprintf("%s/%s/", s3a.option.BucketsPath, bucket) + reqDir = fmt.Sprintf("%s%s", bucketPrefix, reqDir) if strings.HasSuffix(reqDir, "/") { // remove trailing "/" 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 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) { if entry.IsDirectory { if delimiter == "/" { - prefix = fmt.Sprintf("%s%s/", dir, entry.Name) commonPrefixes = append(commonPrefixes, PrefixEntry{ - Prefix: prefix[len(bucketPrefix):], + Prefix: fmt.Sprintf("%s/%s/", dir, entry.Name)[len(bucketPrefix):], }) } } else { 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(), ETag: "\"" + filer2.ETag(entry) + "\"", Size: int64(filer2.FileSize(entry)),