mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
Update s3 checker to iterate through all objects pages (#1802)
This commit is contained in:
@@ -11,10 +11,6 @@ import (
|
||||
"github.com/gomods/athens/pkg/observ"
|
||||
)
|
||||
|
||||
const (
|
||||
s3ErrorCodeNotFound = "NotFound"
|
||||
)
|
||||
|
||||
// Exists implements the (./pkg/storage).Checker interface
|
||||
// returning true if the module at version exists in storage
|
||||
func (s *Storage) Exists(ctx context.Context, module, version string) (bool, error) {
|
||||
@@ -26,12 +22,8 @@ func (s *Storage) Exists(ctx context.Context, module, version string) (bool, err
|
||||
Bucket: aws.String(s.bucket),
|
||||
Prefix: aws.String(fmt.Sprintf("%s/@v", module)),
|
||||
}
|
||||
|
||||
loo, err := s.s3API.ListObjectsWithContext(ctx, lsParams)
|
||||
if err != nil {
|
||||
return false, errors.E(op, err, errors.M(module), errors.V(version))
|
||||
}
|
||||
var count int
|
||||
err := s.s3API.ListObjectsPagesWithContext(ctx, lsParams, func(loo *s3.ListObjectsOutput, lastPage bool) bool {
|
||||
for _, o := range loo.Contents {
|
||||
// sane assumption: no duplicate keys.
|
||||
switch *o.Key {
|
||||
@@ -43,5 +35,12 @@ func (s *Storage) Exists(ctx context.Context, module, version string) (bool, err
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count != 3
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return false, errors.E(op, err, errors.M(module), errors.V(version))
|
||||
}
|
||||
|
||||
return count == 3, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user