Storage Driver: fix s3 compatibility with swift DLO

Signed-off-by: cfanz <songxinying@sensetime.com>
This commit is contained in:
cfanz 2019-10-18 13:40:12 +08:00
parent ae2e973db9
commit f168e4c402

View file

@ -616,9 +616,17 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
if *resp.Contents[0].Key != d.s3Path(path) { if *resp.Contents[0].Key != d.s3Path(path) {
fi.IsDir = true fi.IsDir = true
} else { } 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.IsDir = false
fi.Size = *resp.Contents[0].Size fi.Size = *headResp.ContentLength
fi.ModTime = *resp.Contents[0].LastModified fi.ModTime = *headResp.LastModified
} }
} else if len(resp.CommonPrefixes) == 1 { } else if len(resp.CommonPrefixes) == 1 {
fi.IsDir = true fi.IsDir = true