From f168e4c402b1015d4f9bc076cd4fb34e6956481f Mon Sep 17 00:00:00 2001 From: cfanz Date: Fri, 18 Oct 2019 13:40:12 +0800 Subject: [PATCH] Storage Driver: fix s3 compatibility with swift DLO Signed-off-by: cfanz --- registry/storage/driver/s3-aws/s3.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 4b6c50d7b..4edf4d093 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -616,9 +616,17 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, if *resp.Contents[0].Key != d.s3Path(path) { fi.IsDir = true } else { + // HEAD object to get accurate size for swift DLO + headResp, err := d.S3.HeadObject(&s3.HeadObjectInput{ + Bucket: aws.String(d.Bucket), + Key: aws.String(d.s3Path(path)), + }) + if err != nil { + return nil, storagedriver.InvalidPathError{Path: path} + } fi.IsDir = false - fi.Size = *resp.Contents[0].Size - fi.ModTime = *resp.Contents[0].LastModified + fi.Size = *headResp.ContentLength + fi.ModTime = *headResp.LastModified } } else if len(resp.CommonPrefixes) == 1 { fi.IsDir = true