Skip to content

Commit

Permalink
cmd/uplink: fail server-side copy if --expires is set
Browse files Browse the repository at this point in the history
The object expiration time cannot be changed with server-side copy. It's
better to fail the command instead of confusing the user by ignoring the
flag.

Change-Id: I2ebbc2932e647beea6cbf9f6dfeb94a9e4cb5d64
  • Loading branch information
kaloyan-raev authored and Storj Robot committed Dec 18, 2023
1 parent bb4c19f commit ad2d897
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/uplink/cmd_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ func (c *cmdCp) copyFile(ctx context.Context, fs ulfs.Filesystem, source, dest u
}

if dest.Remote() && source.Remote() {
if !c.expires.IsZero() {
return errs.New("expiration time cannot be changed with server-side copy")
}
return fs.Copy(ctx, source, dest)
}

Expand Down
13 changes: 13 additions & 0 deletions cmd/uplink/cmd_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ func TestCpRemoteToRemote(t *testing.T) {
ultest.File{Loc: "sj://b1/mid-slash//file", Contents: "data8"},
)
})

t.Run("Expires", func(t *testing.T) {
state.Fail(t, "cp", "--expires", "+4h", "sj://b1/ends-slash", "sj://b1/ends-slash-copy").RequireFiles(t,
ultest.File{Loc: "sj://b1/dot-dot/../../../../../foo", Contents: "data1"},
ultest.File{Loc: "sj://b1/dot-dot/../../foo", Contents: "data2"},
ultest.File{Loc: "sj://b1/dot-dot/../foo", Contents: "data3"},
ultest.File{Loc: "sj://b1//starts-slash", Contents: "data4"},
ultest.File{Loc: "sj://b1/ends-slash", Contents: "data5"},
ultest.File{Loc: "sj://b1/ends-slash/", Contents: "data6"},
ultest.File{Loc: "sj://b1/ends-slash//", Contents: "data7"},
ultest.File{Loc: "sj://b1/mid-slash//file", Contents: "data8"},
)
})
}

func TestCpLocalToLocal(t *testing.T) {
Expand Down

0 comments on commit ad2d897

Please sign in to comment.