diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 4b6c50d7b..778027745 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -599,31 +599,26 @@ func (d *driver) Writer(ctx context.Context, path string, append bool) (storaged // Stat retrieves the FileInfo for the given path, including the current size // in bytes and the creation time. func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) { - resp, err := d.S3.ListObjects(&s3.ListObjectsInput{ - Bucket: aws.String(d.Bucket), - Prefix: aws.String(d.s3Path(path)), - MaxKeys: aws.Int64(1), + resp, err := d.S3.HeadObjectWithContext(ctx, &s3.HeadObjectInput{ + Bucket: aws.String(d.Bucket), + Key: aws.String(d.s3Path(path)), }) if err != nil { + if err, ok := err.(awserr.Error); ok && err.Code() == s3.ErrCodeNoSuchKey { + return nil, storagedriver.PathNotFoundError{Path: path} + } return nil, err } fi := storagedriver.FileInfoFields{ - Path: path, + Path: path, + IsDir: false, } - - if len(resp.Contents) == 1 { - if *resp.Contents[0].Key != d.s3Path(path) { - fi.IsDir = true - } else { - fi.IsDir = false - fi.Size = *resp.Contents[0].Size - fi.ModTime = *resp.Contents[0].LastModified - } - } else if len(resp.CommonPrefixes) == 1 { - fi.IsDir = true - } else { - return nil, storagedriver.PathNotFoundError{Path: path} + if resp.ContentLength != nil { + fi.Size = *resp.ContentLength + } + if resp.LastModified != nil { + fi.ModTime = *resp.LastModified } return storagedriver.FileInfoInternal{FileInfoFields: fi}, nil