From 81b212f034b0248d58b9850327400d1684334c5f Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Sun, 21 Oct 2018 01:31:16 +0530 Subject: [PATCH 1/3] Fix bug in mv command --- cmd/mv.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/mv.go b/cmd/mv.go index 5b5c6ba..2a0ac11 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" "os" + "regexp" "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files" "github.com/spf13/cobra" @@ -39,8 +40,10 @@ func mv(cmd *cobra.Command, args []string) error { var mvErrors []error var relocationArgs []*files.RelocationArg + re := regexp.MustCompile("[^/]+$") for _, argument := range argsToMove { - arg, err := makeRelocationArg(argument, destination+"/"+argument) + argumentFile := re.FindString(argument) + arg, err := makeRelocationArg(argument, destination+"/"+argumentFile) if err != nil { relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) mvErrors = append(mvErrors, relocationError) From e2a9c27944be778d8378b275f7da39a5fa1c3ded Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Sun, 21 Oct 2018 05:58:45 +0530 Subject: [PATCH 2/3] Update mv.go to support renaming and add tests --- cmd/mv.go | 23 ++++++++++++++++++----- contrib/test.sh | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cmd/mv.go b/cmd/mv.go index 2a0ac11..d5a338c 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -42,13 +42,26 @@ func mv(cmd *cobra.Command, args []string) error { re := regexp.MustCompile("[^/]+$") for _, argument := range argsToMove { + argumentFile := re.FindString(argument) - arg, err := makeRelocationArg(argument, destination+"/"+argumentFile) - if err != nil { - relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) - mvErrors = append(mvErrors, relocationError) + lastCharDest := destination[len(destination)-1:] + + if lastCharDest == "/" { + arg, err := makeRelocationArg(argument, destination + argumentFile) + if err != nil { + relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) + mvErrors = append(mvErrors, relocationError) + } else { + relocationArgs = append(relocationArgs, arg) + } } else { - relocationArgs = append(relocationArgs, arg) + arg, err := makeRelocationArg(argument, destination) + if err != nil { + relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) + mvErrors = append(mvErrors, relocationError) + } else { + relocationArgs = append(relocationArgs, arg) + } } } diff --git a/contrib/test.sh b/contrib/test.sh index 8e644f3..24cbd87 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -35,8 +35,8 @@ ${dbxcli} cp ${d}/dbxcli ${d}/dbxcli-new echo "Testing revs" rev=$(${dbxcli} revs ${d}/dbxcli) -echo "Testing mv" -${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old +echo "Testing updated mv" +${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old/ echo "Testing restore" ${dbxcli} restore ${d}/dbxcli ${rev} From 4bb9b046ee8218b638601677465cb78186918d7f Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Fri, 26 Oct 2018 21:35:01 +0530 Subject: [PATCH 3/3] Add requested changes in mv.go --- cmd/mv.go | 26 ++++++++++++-------------- contrib/test.sh | 5 ++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmd/mv.go b/cmd/mv.go index d5a338c..7277817 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -46,22 +46,20 @@ func mv(cmd *cobra.Command, args []string) error { argumentFile := re.FindString(argument) lastCharDest := destination[len(destination)-1:] + var err error + var arg *files.RelocationArg + if lastCharDest == "/" { - arg, err := makeRelocationArg(argument, destination + argumentFile) - if err != nil { - relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) - mvErrors = append(mvErrors, relocationError) - } else { - relocationArgs = append(relocationArgs, arg) - } + arg, err = makeRelocationArg(argument, destination + argumentFile) + } else { + arg, err = makeRelocationArg(argument, destination) + } + + if err != nil { + relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) + mvErrors = append(mvErrors, relocationError) } else { - arg, err := makeRelocationArg(argument, destination) - if err != nil { - relocationError := fmt.Errorf("Error validating move for %s to %s: %v", argument, destination, err) - mvErrors = append(mvErrors, relocationError) - } else { - relocationArgs = append(relocationArgs, arg) - } + relocationArgs = append(relocationArgs, arg) } } diff --git a/contrib/test.sh b/contrib/test.sh index 24cbd87..5e7964d 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -35,7 +35,10 @@ ${dbxcli} cp ${d}/dbxcli ${d}/dbxcli-new echo "Testing revs" rev=$(${dbxcli} revs ${d}/dbxcli) -echo "Testing updated mv" +echo "Testing mv" +${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old + +echo "Testing mv" ${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old/ echo "Testing restore"