cmd/uplink: add mv command

New command for cli to move object to different
location.

uplink mv sj://bucket/your-object sj://bucket/moved-object

Change-Id: I85a4961aa59f250819954e78f20363ac3c570938
This commit is contained in:
Michał Niewrzał 2021-09-01 12:04:25 +02:00 committed by Michal Niewrzal
parent 3dbd44347e
commit 0209bc6ef7
5 changed files with 68 additions and 9 deletions

56
cmd/uplink/cmd/mv.go Normal file
View File

@ -0,0 +1,56 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"storj.io/common/fpath"
)
func init() {
addCmd(&cobra.Command{
Use: "mv SOURCE DESTINATION",
Short: "Moves a Storj object to another location in Storj",
RunE: move,
Args: cobra.ExactArgs(2),
}, RootCmd)
}
func move(cmd *cobra.Command, args []string) (err error) {
ctx, _ := withTelemetry(cmd)
src, err := fpath.New(args[0])
if err != nil {
return err
}
dst, err := fpath.New(args[1])
if err != nil {
return err
}
if src.IsLocal() || dst.IsLocal() {
return errors.New("the source and the destination must be a Storj URL")
}
project, err := cfg.getProject(ctx, false)
if err != nil {
return err
}
defer closeProject(project)
err = project.MoveObject(ctx, src.Bucket(), src.Path(), dst.Bucket(), dst.Path(), nil)
if err != nil {
return err
}
fmt.Printf("%s moved to %s\n", src.String(), dst.String())
return nil
}

2
go.mod
View File

@ -65,5 +65,5 @@ require (
storj.io/drpc v0.0.26
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7
storj.io/private v0.0.0-20210810102517-434aeab3f17d
storj.io/uplink v1.5.0-rc.1.0.20210915202907-4aeb0a767a86
storj.io/uplink v1.6.1-0.20210927115829-4da201e4aebb
)

7
go.sum
View File

@ -878,12 +878,11 @@ sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0=
storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog=
storj.io/common v0.0.0-20210915201516-56ad343b6a7e/go.mod h1:i35B7Zr9WpXWSePOUAQXffRgvt0fWKpdfiB5mtbBbaA=
storj.io/common v0.0.0-20210916151047-6aaeb34bb916/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 h1:G0ePy32obot7DamdE/KcwwKcquE2r6T2pG0G6qyhr6Y=
storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/drpc v0.0.25/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/drpc v0.0.26 h1:T6jJzjby7QUa/2XHR1qMxTCENpDHEw4/o+kfDfZQqQI=
storj.io/drpc v0.0.26/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/monkit-jaeger v0.0.0-20210225162224-66fb37637bf6/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
@ -891,5 +890,5 @@ storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 h1:zi0w9zoBfvuqysSAqxJ
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
storj.io/private v0.0.0-20210810102517-434aeab3f17d h1:w51RhoN6WF8zQE1ED3XYfW+Yb7DtlxxJTs0lpLvWRUA=
storj.io/private v0.0.0-20210810102517-434aeab3f17d/go.mod h1:wvudoWSyOyB2daZNaMykjjqsSUad/ttFlUwgelg9+qg=
storj.io/uplink v1.5.0-rc.1.0.20210915202907-4aeb0a767a86 h1:bid/bndO+AH706rPfeNKZoMahyikOmA1zE48rttaezE=
storj.io/uplink v1.5.0-rc.1.0.20210915202907-4aeb0a767a86/go.mod h1:K/7QKH1K0LydqrqmrifHH6NFm47Xth6Mp0AhBZzXUEs=
storj.io/uplink v1.6.1-0.20210927115829-4da201e4aebb h1:wwKsORXE4C3hhfOzPzy3/5UOTV7ziJVUOi27MuzRw24=
storj.io/uplink v1.6.1-0.20210927115829-4da201e4aebb/go.mod h1:zqj/LFDxa6RMaSRSHOmukg3mMgesOry0iHSjNldDMGo=

View File

@ -81,6 +81,11 @@ uplink cp "sj://$BUCKET/diff-size-segments_upl_p2" "$DST_DIR/diff-size-segmen
uplink ls "sj://$BUCKET/small-upload-testfile" | grep "small-upload-testfile"
# test server-side move operation
uplink mv "sj://$BUCKET/big-upload-testfile" "sj://$BUCKET/moved-big-upload-testfile"
uplink ls "sj://$BUCKET/moved-big-upload-testfile" | grep "moved-big-upload-testfile"
uplink mv "sj://$BUCKET/moved-big-upload-testfile" "sj://$BUCKET/big-upload-testfile"
uplink rm "sj://$BUCKET/small-upload-testfile"
uplink rm "sj://$BUCKET/big-upload-testfile"
uplink rm "sj://$BUCKET/multisegment-upload-testfile"

View File

@ -840,12 +840,11 @@ sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0=
storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog=
storj.io/common v0.0.0-20210915201516-56ad343b6a7e/go.mod h1:i35B7Zr9WpXWSePOUAQXffRgvt0fWKpdfiB5mtbBbaA=
storj.io/common v0.0.0-20210916151047-6aaeb34bb916/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 h1:G0ePy32obot7DamdE/KcwwKcquE2r6T2pG0G6qyhr6Y=
storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/drpc v0.0.25/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/drpc v0.0.26 h1:T6jJzjby7QUa/2XHR1qMxTCENpDHEw4/o+kfDfZQqQI=
storj.io/drpc v0.0.26/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/monkit-jaeger v0.0.0-20210225162224-66fb37637bf6/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
@ -853,5 +852,5 @@ storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 h1:zi0w9zoBfvuqysSAqxJ
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
storj.io/private v0.0.0-20210810102517-434aeab3f17d h1:w51RhoN6WF8zQE1ED3XYfW+Yb7DtlxxJTs0lpLvWRUA=
storj.io/private v0.0.0-20210810102517-434aeab3f17d/go.mod h1:wvudoWSyOyB2daZNaMykjjqsSUad/ttFlUwgelg9+qg=
storj.io/uplink v1.5.0-rc.1.0.20210915202907-4aeb0a767a86 h1:bid/bndO+AH706rPfeNKZoMahyikOmA1zE48rttaezE=
storj.io/uplink v1.5.0-rc.1.0.20210915202907-4aeb0a767a86/go.mod h1:K/7QKH1K0LydqrqmrifHH6NFm47Xth6Mp0AhBZzXUEs=
storj.io/uplink v1.6.1-0.20210927115829-4da201e4aebb h1:wwKsORXE4C3hhfOzPzy3/5UOTV7ziJVUOi27MuzRw24=
storj.io/uplink v1.6.1-0.20210927115829-4da201e4aebb/go.mod h1:zqj/LFDxa6RMaSRSHOmukg3mMgesOry0iHSjNldDMGo=