Skip to content

Commit

Permalink
Update mv.go to support renaming and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Oct 21, 2018
1 parent 81b212f commit e2a9c27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions cmd/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit e2a9c27

Please sign in to comment.