Skip to content

Commit

Permalink
chore: add listObjectsResponse IsTruncated check
Browse files Browse the repository at this point in the history
  • Loading branch information
zealllot committed Nov 25, 2024
1 parent 7507fea commit ecff5c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.17.44
github.com/aws/aws-sdk-go-v2/service/s3 v1.67.0
github.com/aws/aws-sdk-go-v2/service/sts v1.32.4
github.com/aws/smithy-go v1.22.0
github.com/jinzhu/configor v1.2.1
github.com/qiniu/api.v7/v7 v7.8.2
)
Expand All @@ -27,7 +28,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect
github.com/aws/smithy-go v1.22.0 // indirect
github.com/gookit/color v1.3.6 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
23 changes: 17 additions & 6 deletions s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,22 @@ func (client Client) DeleteObjects(paths []string) (err error) {
func (client Client) List(path string) ([]*oss.Object, error) {
var objects []*oss.Object
var prefix string
var continuationToken *string

if path != "" {
prefix = strings.Trim(path, "/") + "/"
}

listObjectsResponse, err := client.S3.ListObjectsV2(context.Background(), &s3.ListObjectsV2Input{
Bucket: aws.String(client.Config.Bucket),
Prefix: aws.String(prefix),
})
for {
listObjectsResponse, err := client.S3.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
Bucket: aws.String(client.Config.Bucket),
Prefix: aws.String(prefix),
ContinuationToken: continuationToken,
})
if err != nil {
return nil, err
}

if err == nil {
for _, content := range listObjectsResponse.Contents {
objects = append(objects, &oss.Object{
Path: "/" + client.ToS3Key(*content.Key),
Expand All @@ -250,9 +255,15 @@ func (client Client) List(path string) ([]*oss.Object, error) {
StorageInterface: client,
})
}

if listObjectsResponse.IsTruncated != nil && *listObjectsResponse.IsTruncated {
continuationToken = listObjectsResponse.NextContinuationToken
} else {
break
}
}

return objects, err
return objects, nil
}

// GetEndpoint get endpoint, FileSystem's endpoint is /
Expand Down

0 comments on commit ecff5c5

Please sign in to comment.