Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,14 @@ func (c Copy) shouldOverride(ctx context.Context, srcurl *url.URL, dsturl *url.U
return err
}

dstClient, err := storage.NewClient(ctx, dsturl, c.storageOpts)
// Apply destination-region override so the HEAD request is signed for the
// correct region. Without this, --no-clobber with --destination-region
// sends a mis-signed HEAD that returns HTTP 400 AuthorizationHeaderMalformed.
dstOpts := c.storageOpts
if c.dstRegion != "" {
dstOpts.SetRegion(c.dstRegion)
}
dstClient, err := storage.NewClient(ctx, dsturl, dstOpts)
if err != nil {
return err
}
Expand Down
31 changes: 31 additions & 0 deletions command/cp_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
package command

import (
"context"
"io"
"os"
"testing"

"gotest.tools/v3/assert"

"github.com/peak/s5cmd/v2/storage"
"github.com/peak/s5cmd/v2/storage/url"
)

// TestShouldOverride_NoFlagsIsNoop verifies that shouldOverride returns nil
// immediately when none of the override-gating flags are set. This confirms
// the fast-path remains intact and also serves as a compile-time check that
// the Copy struct fields referenced by shouldOverride (including dstRegion)
// are spelled correctly.
func TestShouldOverride_NoFlagsIsNoop(t *testing.T) {
t.Parallel()

srcURL, _ := url.New("s3://bucket/src.txt")
dstURL, _ := url.New("s3://bucket/dst.txt")

c := Copy{
noClobber: false,
ifSizeDiffer: false,
ifSourceNewer: false,
// dstRegion is set; the fix ensures it would be forwarded to dstOpts
// when the function proceeds past the early return.
dstRegion: "us-west-2",
storageOpts: storage.Options{},
}

// shouldOverride must return nil (no-op) when no override flag is set.
if err := c.shouldOverride(context.Background(), srcURL, dstURL); err != nil {
t.Errorf("expected nil when no override flags set, got %v", err)
}
}

func TestGuessContentType(t *testing.T) {
t.Parallel()

Expand Down
Loading