From e42edc8e8c45a29d302dff9f36654910f070bf95 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 7 May 2018 18:13:17 +0100 Subject: [PATCH] copy, move: Copy single files directly, don't use --files-from work-around Before this change rclone would inefficiently and confusingly read all the files in the source directory when copy or moving a single file. This caused confusion for the users to see log messages about files which weren't part of the sync. After the change the copy and move commands use the new infrastructure made for the copyto and moveto command for single file copy and move. --- cmd/cmd.go | 10 ++++++++++ cmd/copy/copy.go | 8 ++++++-- cmd/move/move.go | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 315a26cca..5aae802a8 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -228,6 +228,16 @@ func NewFsSrcDst(args []string) (fs.Fs, fs.Fs) { return fsrc, fdst } +// NewFsSrcFileDst creates a new src and dst fs from the arguments +// +// The source may be a file, in which case the source Fs and file name is returned +func NewFsSrcFileDst(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs) { + fsrc, srcFileName = NewFsFile(args[0]) + fdst = newFsDir(args[1]) + fs.CalculateModifyWindow(fdst, fsrc) + return fsrc, srcFileName, fdst +} + // NewFsSrcDstFiles creates a new src and dst fs from the arguments // If src is a file then srcFileName and dstFileName will be non-empty func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs, dstFileName string) { diff --git a/cmd/copy/copy.go b/cmd/copy/copy.go index 5b928668f..7b5a93787 100644 --- a/cmd/copy/copy.go +++ b/cmd/copy/copy.go @@ -2,6 +2,7 @@ package copy import ( "github.com/ncw/rclone/cmd" + "github.com/ncw/rclone/fs/operations" "github.com/ncw/rclone/fs/sync" "github.com/spf13/cobra" ) @@ -52,9 +53,12 @@ source or destination. `, Run: func(command *cobra.Command, args []string) { cmd.CheckArgs(2, 2, command, args) - fsrc, fdst := cmd.NewFsSrcDst(args) + fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst(args) cmd.Run(true, true, command, func() error { - return sync.CopyDir(fdst, fsrc) + if srcFileName == "" { + return sync.CopyDir(fdst, fsrc) + } + return operations.CopyFile(fdst, fsrc, srcFileName, srcFileName) }) }, } diff --git a/cmd/move/move.go b/cmd/move/move.go index 5559da866..ca588dc73 100644 --- a/cmd/move/move.go +++ b/cmd/move/move.go @@ -2,6 +2,7 @@ package move import ( "github.com/ncw/rclone/cmd" + "github.com/ncw/rclone/fs/operations" "github.com/ncw/rclone/fs/sync" "github.com/spf13/cobra" ) @@ -41,10 +42,12 @@ If you want to delete empty source directories after move, use the --delete-empt `, Run: func(command *cobra.Command, args []string) { cmd.CheckArgs(2, 2, command, args) - fsrc, fdst := cmd.NewFsSrcDst(args) + fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst(args) cmd.Run(true, true, command, func() error { - - return sync.MoveDir(fdst, fsrc, deleteEmptySrcDirs) + if srcFileName == "" { + return sync.MoveDir(fdst, fsrc, deleteEmptySrcDirs) + } + return operations.MoveFile(fdst, fsrc, srcFileName, srcFileName) }) }, }