S3 FileExists fix

According to https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD
must not have response body so the AWS error code NoSuchKey
cannot be received from S3 and we need to fallback to HTTP NotFound
error code.
This commit is contained in:
Petr Jediný
2018-01-17 11:27:35 +01:00
parent 1aa88701fb
commit 60fb415150

View File

@@ -20,6 +20,8 @@ import (
"github.com/smira/go-aws-auth"
)
const errCodeNotFound = "NotFound"
// PublishedStorage abstract file system with published files (actually hosted on S3)
type PublishedStorage struct {
s3 *s3.S3
@@ -429,7 +431,7 @@ func (storage *PublishedStorage) FileExists(path string) (bool, error) {
_, err := storage.s3.HeadObject(params)
if err != nil {
aerr, ok := err.(awserr.Error)
if ok && aerr.Code() == s3.ErrCodeNoSuchKey {
if ok && aerr.Code() == errCodeNotFound {
return false, nil
}