Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cp command for a single source avoid preserving the original folder structure #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
dbxcli.exe
11 changes: 10 additions & 1 deletion cmd/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ import (
func cp(cmd *cobra.Command, args []string) error {
var destination string
var argsToCopy []string
var keepOriginalFolderStructure bool

if len(args) > 2 {
destination = args[len(args)-1]
argsToCopy = args[0 : len(args)-1]
keepOriginalFolderStructure = true
} else if len(args) == 2 {
destination = args[1]
argsToCopy = append(argsToCopy, args[0])
keepOriginalFolderStructure = false
} else {
return errors.New("cp requires a source and a destination")
}
Expand All @@ -41,7 +44,13 @@ func cp(cmd *cobra.Command, args []string) error {
var relocationArgs []*files.RelocationArg

for _, argument := range argsToCopy {
arg, err := makeRelocationArg(argument, destination+"/"+argument)
var actualDestination string
if keepOriginalFolderStructure {
actualDestination = destination + "/" + argument
} else {
actualDestination = destination
}
arg, err := makeRelocationArg(argument, actualDestination)
if err != nil {
relocationError := fmt.Errorf("Error validating copy for %s to %s: %v", argument, destination, err)
cpErrors = append(cpErrors, relocationError)
Expand Down