summaryrefslogtreecommitdiff
path: root/aws.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-01-26 14:56:10 +0000
committerNick White <git@njw.name>2021-01-26 14:56:10 +0000
commit5c3cee66a90ce6ef87e125b3bf011a6903d38083 (patch)
treebe1347c79389b232150227bd8489db3fabb415ac /aws.go
parent54150b54cd06e3deba44e73b151070b74a4d8e76 (diff)
Make ListObjectsWithMeta generic again and create a specialised ListObjectWithMeta for single file listing, so we can still be as fast, but do not have a misleading api
Diffstat (limited to 'aws.go')
-rw-r--r--aws.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/aws.go b/aws.go
index dd74a01..035b08a 100644
--- a/aws.go
+++ b/aws.go
@@ -355,16 +355,35 @@ func (a *AwsConn) ListObjectsWithMeta(bucket string, prefix string) ([]ObjMeta,
err := a.s3svc.ListObjectsV2Pages(&s3.ListObjectsV2Input{
Bucket: aws.String(bucket),
Prefix: aws.String(prefix),
- MaxKeys: aws.Int64(1),
}, func(page *s3.ListObjectsV2Output, last bool) bool {
for _, r := range page.Contents {
objs = append(objs, ObjMeta{Name: *r.Key, Date: *r.LastModified})
}
- return false // only process the first page as that's all we need
+ return true
})
return objs, err
}
+// ListObjectWithMeta lists the name and last modified date of the
+// first object with the specified prefix.
+func (a *AwsConn) ListObjectWithMeta(bucket string, prefix string) (ObjMeta, error) {
+ var obj ObjMeta
+ err := a.s3svc.ListObjectsV2Pages(&s3.ListObjectsV2Input{
+ Bucket: aws.String(bucket),
+ Prefix: aws.String(prefix),
+ MaxKeys: aws.Int64(1),
+ }, func(page *s3.ListObjectsV2Output, last bool) bool {
+ for _, r := range page.Contents {
+ obj = ObjMeta{Name: *r.Key, Date: *r.LastModified}
+ }
+ return false
+ })
+ if obj.Name == "" && obj.Date.IsZero() && err == nil {
+ return obj, fmt.Errorf("No object could be found for %s", prefix)
+ }
+ return obj, err
+}
+
func (a *AwsConn) ListObjectPrefixes(bucket string) ([]string, error) {
var prefixes []string
err := a.s3svc.ListObjectsV2Pages(&s3.ListObjectsV2Input{