mirror of
https://github.com/rclone/rclone.git
synced 2024-11-30 04:15:26 +01:00
57d5de6fba
git grep -l github.com/ncw/rclone | xargs -d'\n' perl -i~ -lpe 's|github.com/ncw/rclone|github.com/rclone/rclone|g' goimports -w `find . -name \*.go`
65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
package move
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs/operations"
|
|
"github.com/rclone/rclone/fs/sync"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Globals
|
|
var (
|
|
deleteEmptySrcDirs = false
|
|
createEmptySrcDirs = false
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefintion)
|
|
commandDefintion.Flags().BoolVarP(&deleteEmptySrcDirs, "delete-empty-src-dirs", "", deleteEmptySrcDirs, "Delete empty source dirs after move")
|
|
commandDefintion.Flags().BoolVarP(&createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after move")
|
|
}
|
|
|
|
var commandDefintion = &cobra.Command{
|
|
Use: "move source:path dest:path",
|
|
Short: `Move files from source to dest.`,
|
|
Long: `
|
|
Moves the contents of the source directory to the destination
|
|
directory. Rclone will error if the source and destination overlap and
|
|
the remote does not support a server side directory move operation.
|
|
|
|
If no filters are in use and if possible this will server side move
|
|
` + "`source:path`" + ` into ` + "`dest:path`" + `. After this ` + "`source:path`" + ` will no
|
|
longer longer exist.
|
|
|
|
Otherwise for each file in ` + "`source:path`" + ` selected by the filters (if
|
|
any) this will move it into ` + "`dest:path`" + `. If possible a server side
|
|
move will be used, otherwise it will copy it (server side if possible)
|
|
into ` + "`dest:path`" + ` then delete the original (if no errors on copy) in
|
|
` + "`source:path`" + `.
|
|
|
|
If you want to delete empty source directories after move, use the --delete-empty-src-dirs flag.
|
|
|
|
See the [--no-traverse](/docs/#no-traverse) option for controlling
|
|
whether rclone lists the destination directory or not. Supplying this
|
|
option when moving a small number of files into a large destination
|
|
can speed transfers up greatly.
|
|
|
|
**Important**: Since this can cause data loss, test first with the
|
|
--dry-run flag.
|
|
|
|
**Note**: Use the ` + "`-P`" + `/` + "`--progress`" + ` flag to view real-time transfer statistics.
|
|
`,
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(2, 2, command, args)
|
|
fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst(args)
|
|
cmd.Run(true, true, command, func() error {
|
|
if srcFileName == "" {
|
|
return sync.MoveDir(context.Background(), fdst, fsrc, deleteEmptySrcDirs, createEmptySrcDirs)
|
|
}
|
|
return operations.MoveFile(context.Background(), fdst, fsrc, srcFileName, srcFileName)
|
|
})
|
|
},
|
|
}
|