Skip to content

Commit

Permalink
Merge pull request #105 from vaithak/master
Browse files Browse the repository at this point in the history
Fix bug in moving files between subfolders.
  • Loading branch information
diwakergupta authored Dec 5, 2018
2 parents 31654c9 + 4bb9b04 commit f0a17d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"os"
"regexp"

"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files"
"github.com/spf13/cobra"
Expand All @@ -39,8 +40,21 @@ 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)
lastCharDest := destination[len(destination)-1:]

var err error
var arg *files.RelocationArg

if lastCharDest == "/" {
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)
Expand Down
3 changes: 3 additions & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ rev=$(${dbxcli} revs ${d}/dbxcli)
echo "Testing mv"
${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old

echo "Testing mv"
${dbxcli} mv ${d}/dbxcli ${d}/dbxcli-old/

echo "Testing restore"
${dbxcli} restore ${d}/dbxcli ${rev}

Expand Down

0 comments on commit f0a17d9

Please sign in to comment.