mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
operations: make move and copy individual files obey --backup-dir
Before this change, when using rclone copy or move with --backup-dir and the source was a single file, rclone would fail to use the backup directory. This change looks up the backup directory in the Fs cache and uses it as appropriate. This affects any commands which call operations.MoveFile or operations.CopyFile which includes rclone move/moveto/copy/copyto where the source is a single file. Fixes #3219
This commit is contained in:
@@ -739,6 +739,29 @@ func TestMoveFile(t *testing.T) {
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
}
|
||||
|
||||
func TestMoveFileBackupDir(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
oldBackupDir := fs.Config.BackupDir
|
||||
fs.Config.BackupDir = r.FremoteName + "/backup"
|
||||
defer func() {
|
||||
fs.Config.BackupDir = oldBackupDir
|
||||
}()
|
||||
|
||||
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
file1old := r.WriteObject("dst/file1", "file1 contents old", t1)
|
||||
fstest.CheckItems(t, r.Fremote, file1old)
|
||||
|
||||
err := operations.MoveFile(r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
file1old.Path = "backup/dst/file1"
|
||||
fstest.CheckItems(t, r.Fremote, file1old, file1)
|
||||
}
|
||||
|
||||
func TestCopyFile(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
@@ -765,6 +788,29 @@ func TestCopyFile(t *testing.T) {
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
}
|
||||
|
||||
func TestCopyFileBackupDir(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
oldBackupDir := fs.Config.BackupDir
|
||||
fs.Config.BackupDir = r.FremoteName + "/backup"
|
||||
defer func() {
|
||||
fs.Config.BackupDir = oldBackupDir
|
||||
}()
|
||||
|
||||
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
file1old := r.WriteObject("dst/file1", "file1 contents old", t1)
|
||||
fstest.CheckItems(t, r.Fremote, file1old)
|
||||
|
||||
err := operations.CopyFile(r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
file1old.Path = "backup/dst/file1"
|
||||
fstest.CheckItems(t, r.Fremote, file1old, file1)
|
||||
}
|
||||
|
||||
// testFsInfo is for unit testing fs.Info
|
||||
type testFsInfo struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user