0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-22 01:00:40 +00:00

try to handle 404s correctly

This commit is contained in:
Nathan LaFreniere 2015-12-31 12:19:34 -08:00
parent 742f2b5e17
commit 32a26aa1a4

34
aws.go
View File

@ -9,6 +9,7 @@ import (
"path/filepath"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
@ -98,11 +99,23 @@ func (a *AWS) Upload(local, remote string) error {
Bucket: aws.String(a.vargs.Bucket),
Key: aws.String(remote),
})
if err != nil {
if err != nil && err.(awserr.Error).Code() != "404" {
if err.(awserr.Error).Code() == "404" {
return err
}
debug("Uploading \"%s\" with Content-Type \"%s\" and permissions \"%s\"", local, contentType, access)
_, err = a.client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(a.vargs.Bucket),
Key: aws.String(remote),
Body: file,
ContentType: aws.String(contentType),
ACL: aws.String(access),
Metadata: metadata,
})
return err
}
if head != nil {
hash := md5.New()
io.Copy(hash, file)
sum := fmt.Sprintf("\"%x\"", hash.Sum(nil))
@ -188,22 +201,7 @@ func (a *AWS) Upload(local, remote string) error {
return err
}
_, err = file.Seek(0, 0)
if err != nil {
return err
}
}
debug("Uploading \"%s\" with Content-Type \"%s\" and permissions \"%s\"", local, contentType, access)
_, err = a.client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(a.vargs.Bucket),
Key: aws.String(remote),
Body: file,
ContentType: aws.String(contentType),
ACL: aws.String(access),
Metadata: metadata,
})
return err
return nil
}
func (a *AWS) Redirect(path, location string) error {