mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 11:44:45 -06:00
Retry on XAmzContentSHA256Mismatch
This commit is contained in:
@@ -5,6 +5,9 @@
|
|||||||
package duplicacy
|
package duplicacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
@@ -227,15 +230,26 @@ func (storage *S3Storage) DownloadFile(threadIndex int, filePath string, chunk *
|
|||||||
// UploadFile writes 'content' to the file at 'filePath'.
|
// UploadFile writes 'content' to the file at 'filePath'.
|
||||||
func (storage *S3Storage) UploadFile(threadIndex int, filePath string, content []byte) (err error) {
|
func (storage *S3Storage) UploadFile(threadIndex int, filePath string, content []byte) (err error) {
|
||||||
|
|
||||||
input := &s3.PutObjectInput {
|
attempts := 0
|
||||||
Bucket: aws.String(storage.bucket),
|
|
||||||
Key: aws.String(storage.storageDir + filePath),
|
for {
|
||||||
ACL: aws.String(s3.ObjectCannedACLPrivate),
|
input := &s3.PutObjectInput {
|
||||||
Body: CreateRateLimitedReader(content, storage.UploadRateLimit / len(storage.bucket)),
|
Bucket: aws.String(storage.bucket),
|
||||||
ContentType: aws.String("application/duplicacy"),
|
Key: aws.String(storage.storageDir + filePath),
|
||||||
|
ACL: aws.String(s3.ObjectCannedACLPrivate),
|
||||||
|
Body: CreateRateLimitedReader(content, storage.UploadRateLimit / len(storage.bucket)),
|
||||||
|
ContentType: aws.String("application/duplicacy"),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = storage.client.PutObject(input)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user