Skip to content

Commit

Permalink
s3: fall back to old stat
Browse files Browse the repository at this point in the history
  • Loading branch information
dhij committed Aug 18, 2023
1 parent 61619ac commit 0b0d4fc
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions registry/storage/driver/s3-aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,27 @@ func (d *driver) Writer(ctx context.Context, path string, append bool) (storaged
// in bytes and the creation time.
func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) {
s := d.s3Client(ctx)
resp, err := s.ListObjectsV2(&s3.ListObjectsV2Input{

fi := storagedriver.FileInfoFields{
Path: path,
}

headResp, err := s.HeadObjectWithContext(ctx, &s3.HeadObjectInput{
Bucket: aws.String(d.Bucket),
Key: aws.String(d.s3Path(path)),
})
if err == nil && headResp.ContentLength != nil {
if headResp.ContentLength != nil {
fi.Size = *headResp.ContentLength
}
if headResp.LastModified != nil {
fi.ModTime = *headResp.LastModified
}

return storagedriver.FileInfoInternal{FileInfoFields: fi}, nil
}

resp, err := s.ListObjectsWithContext(ctx, &s3.ListObjectsInput{
Bucket: aws.String(d.Bucket),
Prefix: aws.String(d.s3Path(path)),
MaxKeys: aws.Int64(1),
Expand All @@ -835,10 +855,6 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
return nil, err
}

fi := storagedriver.FileInfoFields{
Path: path,
}

if len(resp.Contents) == 1 {
if *resp.Contents[0].Key != d.s3Path(path) {
fi.IsDir = true
Expand Down

0 comments on commit 0b0d4fc

Please sign in to comment.