Skip to content

Commit

Permalink
[skbn/s3] get full list of items, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Jan 8, 2019
1 parent 42781bd commit f3f8aee
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions pkg/skbn/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,22 @@ func GetListOfFilesFromS3(iClient interface{}, path string) ([]string, error) {
}
bucket, s3Path := initS3Variables(pSplit)

attempts := 3
attempt := 0
for attempt < attempts {
attempt++

objectOutput, err := s3.New(s).ListObjects(&s3.ListObjectsInput{
Bucket: aws.String(bucket),
Prefix: aws.String(s3Path),
})
if err != nil {
if attempt == attempts {
return nil, err
}
utils.Sleep(attempt)
continue
}

var outLines []string
for _, content := range objectOutput.Contents {
line := *content.Key
var outLines []string
err := s3.New(s).ListObjectsPages(&s3.ListObjectsInput{
Bucket: aws.String(bucket),
Prefix: aws.String(s3Path),
}, func(p *s3.ListObjectsOutput, last bool) (shouldContinue bool) {
for _, obj := range p.Contents {
line := *obj.Key
outLines = append(outLines, strings.Replace(line, s3Path, "", 1))
}

return outLines, nil
return true
})
if err != nil {
return nil, err
}

return nil, nil
return outLines, nil
}

// DownloadFromS3 downloads a single file from S3
Expand Down

0 comments on commit f3f8aee

Please sign in to comment.