Skip to content

Commit

Permalink
fix CopyObject to use simple CopyObject call, instead of multipart fo…
Browse files Browse the repository at this point in the history
…r zero object size, for backup S3 disks
  • Loading branch information
Slach committed Dec 8, 2023
1 parent 97ed0d0 commit d79255f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v2.4.12
BUG FIXES
- fix CopyObject to use simple CopyObject call, instead of multipart for zero object size, for backup S3 disks

# v2.4.11
BUG FIXES
- fix CopyObject multipart upload complete Parts must be ordered by part number, for backup S3 disks
Expand Down
17 changes: 16 additions & 1 deletion pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func (s *S3) remotePager(ctx context.Context, s3Path string, recursive bool, pro
}

func (s *S3) CopyObject(ctx context.Context, srcBucket, srcKey, dstKey string) (int64, error) {
s.Log.Debugf("S3->CopyObject %s/%s -> %s/%s", srcBucket, srcKey, s.Config.Bucket, dstKey)
dstKey = path.Join(s.Config.ObjectDiskPath, dstKey)
if strings.Contains(s.Config.Endpoint, "storage.googleapis.com") {
params := &s3.CopyObjectInput{
Expand Down Expand Up @@ -487,6 +488,21 @@ func (s *S3) CopyObject(ctx context.Context, srcBucket, srcKey, dstKey string) (
return 0, err
}
srcSize := *sourceObjResp.ContentLength
// just copy object without multipart
if srcSize == 0 {
params := &s3.CopyObjectInput{
Bucket: aws.String(s.Config.Bucket),
Key: aws.String(dstKey),
CopySource: aws.String(path.Join(srcBucket, srcKey)),
StorageClass: s3types.StorageClass(strings.ToUpper(s.Config.StorageClass)),
}
s.enrichCopyObjectParams(params)
_, err := s.client.CopyObject(ctx, params)
if err != nil {
return 0, err
}
return srcSize, nil
}
// Initiate a multipart upload
createMultipartUploadParams := &s3.CreateMultipartUploadInput{
Bucket: aws.String(s.Config.Bucket),
Expand Down Expand Up @@ -594,7 +610,6 @@ func (s *S3) CopyObject(ctx context.Context, srcBucket, srcKey, dstKey string) (
if err != nil {
return 0, fmt.Errorf("complete CopyObject multipart upload: %v", err)
}
s.Log.Debugf("S3->CopyObject %s/%s -> %s/%s", srcBucket, srcKey, s.Config.Bucket, dstKey)
return srcSize, nil
}

Expand Down

0 comments on commit d79255f

Please sign in to comment.