diff options
author | Nick White <git@njw.name> | 2021-02-01 11:45:27 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-02-01 11:45:27 +0000 |
commit | 16ea8034794ef030c969d586a7fc945bf4a2873a (patch) | |
tree | ba03a27df08ea0b670d64b69fea6597ebd11ce6d /aws.go | |
parent | 5c3cee66a90ce6ef87e125b3bf011a6903d38083 (diff) |
Ensure DeleteObjects can handle over 1000 files to delete; fixes rmbook for large books
Diffstat (limited to 'aws.go')
-rw-r--r-- | aws.go | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -401,9 +401,25 @@ func (a *AwsConn) ListObjectPrefixes(bucket string) ([]string, error) { // Deletes a list of objects func (a *AwsConn) DeleteObjects(bucket string, keys []string) error { objs := []*s3.ObjectIdentifier{} - for _, v := range keys { + for i, v := range keys { o := s3.ObjectIdentifier{Key: aws.String(v)} objs = append(objs, &o) + // s3.DeleteObjects can only take up to 1000 keys at a time, + // so if necessary delete those collected so far and empty + // the objs queue + if i % 1000 == 1 { + _, err := a.s3svc.DeleteObjects(&s3.DeleteObjectsInput{ + Bucket: aws.String(bucket), + Delete: &s3.Delete{ + Objects: objs, + Quiet: aws.Bool(true), + }, + }) + if err != nil { + return err + } + objs = []*s3.ObjectIdentifier{} + } } _, err := a.s3svc.DeleteObjects(&s3.DeleteObjectsInput{ Bucket: aws.String(bucket), |