Retry on XAmzContentSHA256Mismatch

This commit is contained in:
Gilbert Chen
2017-09-08 19:46:27 -04:00
parent 3f83890859
commit 8808ad5c28

View File

@@ -5,6 +5,9 @@
package duplicacy
import (
"strings"
"reflect"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
@@ -227,6 +230,9 @@ func (storage *S3Storage) DownloadFile(threadIndex int, filePath string, chunk *
// UploadFile writes 'content' to the file at 'filePath'.
func (storage *S3Storage) UploadFile(threadIndex int, filePath string, content []byte) (err error) {
attempts := 0
for {
input := &s3.PutObjectInput {
Bucket: aws.String(storage.bucket),
Key: aws.String(storage.storageDir + filePath),
@@ -236,6 +242,14 @@ func (storage *S3Storage) UploadFile(threadIndex int, filePath string, content [
}
_, err = storage.client.PutObject(input)
if err == nil || attempts >= 3 || !strings.Contains(err.Error(), "XAmzContentSHA256Mismatch") {
return err
}
LOG_INFO("S3_RETRY", "Retrying on %s: %v", reflect.TypeOf(err), err)
attempts += 1
}
return err
}