Skip to content

Commit f3f8aee

Browse files
committed
[skbn/s3] get full list of items, fixes #7
1 parent 42781bd commit f3f8aee

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

pkg/skbn/s3.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,22 @@ func GetListOfFilesFromS3(iClient interface{}, path string) ([]string, error) {
6161
}
6262
bucket, s3Path := initS3Variables(pSplit)
6363

64-
attempts := 3
65-
attempt := 0
66-
for attempt < attempts {
67-
attempt++
68-
69-
objectOutput, err := s3.New(s).ListObjects(&s3.ListObjectsInput{
70-
Bucket: aws.String(bucket),
71-
Prefix: aws.String(s3Path),
72-
})
73-
if err != nil {
74-
if attempt == attempts {
75-
return nil, err
76-
}
77-
utils.Sleep(attempt)
78-
continue
79-
}
80-
81-
var outLines []string
82-
for _, content := range objectOutput.Contents {
83-
line := *content.Key
64+
var outLines []string
65+
err := s3.New(s).ListObjectsPages(&s3.ListObjectsInput{
66+
Bucket: aws.String(bucket),
67+
Prefix: aws.String(s3Path),
68+
}, func(p *s3.ListObjectsOutput, last bool) (shouldContinue bool) {
69+
for _, obj := range p.Contents {
70+
line := *obj.Key
8471
outLines = append(outLines, strings.Replace(line, s3Path, "", 1))
8572
}
86-
87-
return outLines, nil
73+
return true
74+
})
75+
if err != nil {
76+
return nil, err
8877
}
8978

90-
return nil, nil
79+
return outLines, nil
9180
}
9281

9382
// DownloadFromS3 downloads a single file from S3

0 commit comments

Comments
 (0)