// Test a server side move if possible, or the backup path if not func TestServerSideMove(t *testing.T) { r := NewRun(t) defer r.Finalise() file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1) file2 := r.WriteBoth("empty space", "", t2) fstest.CheckItems(t, r.fremote, file2, file1) fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir) require.NoError(t, err) defer finaliseMove() t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove) // Write just one file in the new remote r.WriteObjectTo(fremoteMove, "empty space", "", t2, false) fstest.CheckItems(t, fremoteMove, file2) // Do server side move fs.Stats.ResetCounters() err = fs.MoveDir(fremoteMove, r.fremote) require.NoError(t, err) fstest.CheckItems(t, r.fremote) fstest.CheckItems(t, fremoteMove, file2, file1) // Move it back again, dst does not exist this time fs.Stats.ResetCounters() err = fs.MoveDir(r.fremote, fremoteMove) require.NoError(t, err) fstest.CheckItems(t, r.fremote, file2, file1) fstest.CheckItems(t, fremoteMove) }
// Test a server side move with overlap func TestServerSideMoveOverlap(t *testing.T) { r := NewRun(t) defer r.Finalise() if r.fremote.Features().DirMove != nil { t.Skip("Skipping test as remote supports DirMove") } subRemoteName := r.fremoteName + "/rclone-move-test" fremoteMove, err := fs.NewFs(subRemoteName) require.NoError(t, err) file1 := r.WriteObject("potato2", "------------------------------------------------------------", t1) fstest.CheckItems(t, r.fremote, file1) // Subdir move with no filters should return ErrorCantMoveOverlapping err = fs.MoveDir(fremoteMove, r.fremote) assert.EqualError(t, err, fs.ErrorCantMoveOverlapping.Error()) // Now try with a filter which should also fail with ErrorCantMoveOverlapping fs.Config.Filter.MinSize = 40 defer func() { fs.Config.Filter.MinSize = -1 }() err = fs.MoveDir(fremoteMove, r.fremote) assert.EqualError(t, err, fs.ErrorCantMoveOverlapping.Error()) }
// Test a server side move if possible, or the backup path if not func TestServerSideMove(t *testing.T) { fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir) if err != nil { t.Fatalf("Failed to open remote move %q: %v", *RemoteName, err) } defer finaliseMove() t.Logf("Server side move (if possible) %v -> %v", fremote, fremoteMove) // Start with a copy err = fs.CopyDir(fremoteMove, fremote) if err != nil { t.Fatalf("Server Side Copy failed: %v", err) } // Remove one file obj := fremoteMove.NewFsObject("potato2") if obj == nil { t.Fatalf("Failed to find potato2") } err = obj.Remove() if err != nil { t.Fatalf("Failed to remove object: %v", err) } // Do server side move err = fs.MoveDir(fremoteMove, fremote) if err != nil { t.Fatalf("Server Side Move failed: %v", err) } items := []fstest.Item{ {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"}, } fstest.CheckListingWithPrecision(t, fremote, items[:0], fs.Config.ModifyWindow) fstest.CheckListingWithPrecision(t, fremoteMove, items, fs.Config.ModifyWindow) // Move it back again, dst does not exist this time err = fs.MoveDir(fremote, fremoteMove) if err != nil { t.Fatalf("Server Side Move 2 failed: %v", err) } fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow) fstest.CheckListingWithPrecision(t, fremoteMove, items[:0], fs.Config.ModifyWindow) }
// Test a server side move if possible, or the backup path if not func testServerSideMove(t *testing.T, r *Run, fremoteMove fs.Fs, withFilter bool) { file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1) file2 := r.WriteBoth("empty space", "", t2) file3u := r.WriteBoth("potato3", "------------------------------------------------------------ UPDATED", t2) fstest.CheckItems(t, r.fremote, file2, file1, file3u) t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove) // Write just one file in the new remote r.WriteObjectTo(fremoteMove, "empty space", "", t2, false) file3 := r.WriteObjectTo(fremoteMove, "potato3", "------------------------------------------------------------", t1, false) fstest.CheckItems(t, fremoteMove, file2, file3) // Do server side move fs.Stats.ResetCounters() err := fs.MoveDir(fremoteMove, r.fremote) require.NoError(t, err) if withFilter { fstest.CheckItems(t, r.fremote, file2) } else { fstest.CheckItems(t, r.fremote) } fstest.CheckItems(t, fremoteMove, file2, file1, file3u) // Purge the original before moving require.NoError(t, fs.Purge(r.fremote)) // Move it back again, dst does not exist this time fs.Stats.ResetCounters() err = fs.MoveDir(r.fremote, fremoteMove) require.NoError(t, err) if withFilter { fstest.CheckItems(t, r.fremote, file1, file3u) fstest.CheckItems(t, fremoteMove, file2) } else { fstest.CheckItems(t, r.fremote, file2, file1, file3u) fstest.CheckItems(t, fremoteMove) } }
// Test a server side move if possible, or the backup path if not func TestServerSideMove(t *testing.T) { r := NewRun(t) defer r.Finalise() file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1) file2 := r.WriteBoth("empty space", "", t2) fstest.CheckItems(t, r.fremote, file2, file1) fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir) if err != nil { t.Fatalf("Failed to open remote move %q: %v", *RemoteName, err) } defer finaliseMove() t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove) // Write just one file in the new remote r.WriteObjectTo(fremoteMove, "empty space", "", t2) fstest.CheckItems(t, fremoteMove, file2) // Do server side move err = fs.MoveDir(fremoteMove, r.fremote) if err != nil { t.Fatalf("Server Side Move failed: %v", err) } fstest.CheckItems(t, r.fremote) fstest.CheckItems(t, fremoteMove, file2, file1) // Move it back again, dst does not exist this time err = fs.MoveDir(r.fremote, fremoteMove) if err != nil { t.Fatalf("Server Side Move 2 failed: %v", err) } fstest.CheckItems(t, r.fremote, file2, file1) fstest.CheckItems(t, fremoteMove) }
return fs.Sync(fdst, fsrc) }, MinArgs: 2, MaxArgs: 2, Retry: true, }, { Name: "move", ArgsHelp: "source:path dest:path", Help: ` Moves the source to the destination. This is equivalent to a copy followed by a purge, but may use server side operations to speed it up. Since this can cause data loss, test first with the --dry-run flag.`, Run: func(fdst, fsrc fs.Fs) error { return fs.MoveDir(fdst, fsrc) }, MinArgs: 2, MaxArgs: 2, Retry: true, }, { Name: "ls", ArgsHelp: "[remote:path]", Help: ` List all the objects in the the path with size and path.`, Run: func(fdst, fsrc fs.Fs) error { return fs.List(fdst, os.Stdout) }, MinArgs: 1, MaxArgs: 1,