Allow overlapping remotes in move when DirMove is supported

This commit is contained in:
Nick Craig-Wood 2016-10-22 17:53:52 +01:00
parent 50b3cfccb1
commit 2058652fa4
3 changed files with 14 additions and 7 deletions

View File

@ -15,7 +15,8 @@ var commandDefintion = &cobra.Command{
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.
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

View File

@ -455,12 +455,6 @@ func MoveDir(fdst, fsrc Fs) error {
ErrorLog(fdst, "Nothing to do as source and destination are the same")
return nil
}
// The two remotes mustn't overlap
if Overlapping(fdst, fsrc) {
err := ErrorCantMoveOverlapping
ErrorLog(fdst, "%v", err)
return err
}
// First attempt to use DirMover if exists, same Fs and no filters are active
if fdstDirMover, ok := fdst.(DirMover); ok && fsrc.Name() == fdst.Name() && Config.Filter.InActive() {
@ -483,6 +477,13 @@ func MoveDir(fdst, fsrc Fs) error {
}
}
// The two remotes mustn't overlap if we didn't do server side move
if Overlapping(fdst, fsrc) {
err := ErrorCantMoveOverlapping
ErrorLog(fdst, "%v", err)
return err
}
// Otherwise move the files one by one
return moveDir(fdst, fsrc)
}

View File

@ -671,6 +671,11 @@ func TestServerSideMoveWithFilter(t *testing.T) {
func TestServerSideMoveOverlap(t *testing.T) {
r := NewRun(t)
defer r.Finalise()
if _, ok := r.fremote.(fs.DirMover); ok {
t.Skip("Skipping test as remote supports DirMove")
}
subRemoteName := r.fremoteName + "/rclone-move-test"
fremoteMove, err := fs.NewFs(subRemoteName)
require.NoError(t, err)