Skip to content

Commit

Permalink
add check for prefix in listing s3 objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Vlasic committed Sep 29, 2021
1 parent 4e49323 commit 2cef619
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"mime"
"path/filepath"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -41,6 +42,12 @@ func (a *AWS) DeleteInS3Bucket(name string, prefix string) error {
Bucket: aws.String(name),
}

// add / at the end of prefix if it it's not present
// ListObjectsV2 ignores everything after last / in the string
if prefix != "" && !strings.HasSuffix(prefix, "/") {
prefix = fmt.Sprintf("%s/", prefix)
}

if prefix != "" {
loi.Prefix = aws.String(prefix)
}
Expand Down

0 comments on commit 2cef619

Please sign in to comment.