2016-07-04 14:12:33 +02:00
|
|
|
// Test sync/copy/move
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
package sync
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2017-09-17 15:05:33 +02:00
|
|
|
"runtime"
|
2016-07-04 14:12:33 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
_ "github.com/ncw/rclone/backend/all" // import all backends
|
2016-07-04 14:12:33 +02:00
|
|
|
"github.com/ncw/rclone/fs"
|
2018-01-12 17:30:54 +01:00
|
|
|
"github.com/ncw/rclone/fs/accounting"
|
|
|
|
"github.com/ncw/rclone/fs/filter"
|
2019-02-14 13:06:26 +01:00
|
|
|
"github.com/ncw/rclone/fs/fserrors"
|
2018-01-12 17:30:54 +01:00
|
|
|
"github.com/ncw/rclone/fs/hash"
|
|
|
|
"github.com/ncw/rclone/fs/operations"
|
2016-07-04 14:12:33 +02:00
|
|
|
"github.com/ncw/rclone/fstest"
|
2019-03-21 12:24:13 +01:00
|
|
|
"github.com/pkg/errors"
|
2016-07-04 14:12:33 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2017-09-08 17:19:41 +02:00
|
|
|
"golang.org/x/text/unicode/norm"
|
2016-07-04 14:12:33 +02:00
|
|
|
)
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
// Some times used in the tests
|
|
|
|
var (
|
|
|
|
t1 = fstest.Time("2001-02-03T04:05:06.499999999Z")
|
|
|
|
t2 = fstest.Time("2011-12-25T12:59:59.123456789Z")
|
|
|
|
t3 = fstest.Time("2011-12-30T12:59:59.000000000Z")
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestMain drives the tests
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
fstest.TestMain(m)
|
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
// Check dry run is working
|
|
|
|
func TestCopyWithDryRun(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
fs.Config.DryRun = true
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
fs.Config.DryRun = false
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now without dry run
|
|
|
|
func TestCopy(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-20 13:50:25 +02:00
|
|
|
func TestCopyMissingDirectory(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
|
|
|
|
|
|
|
nonExistingFs, err := fs.NewFs("/non-existing")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = CopyDir(context.Background(), r.Fremote, nonExistingFs, false)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
2018-11-25 17:49:38 +01:00
|
|
|
// Now with --no-traverse
|
|
|
|
func TestCopyNoTraverse(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.NoTraverse = true
|
|
|
|
defer func() { fs.Config.NoTraverse = false }()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2018-11-25 17:49:38 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now with --no-traverse
|
|
|
|
func TestSyncNoTraverse(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.NoTraverse = true
|
|
|
|
defer func() { fs.Config.NoTraverse = false }()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2018-11-25 17:49:38 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
// Test copy with depth
|
|
|
|
func TestCopyWithDepth(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
|
|
|
file2 := r.WriteFile("hello world2", "hello world2", t2)
|
|
|
|
|
|
|
|
// Check the MaxDepth too
|
|
|
|
fs.Config.MaxDepth = 1
|
|
|
|
defer func() { fs.Config.MaxDepth = -1 }()
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 18:41:14 +02:00
|
|
|
// Test copy with files from
|
2019-02-13 18:14:51 +01:00
|
|
|
func testCopyWithFilesFrom(t *testing.T, noTraverse bool) {
|
2018-10-19 18:41:14 +02:00
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("potato2", "hello world", t1)
|
|
|
|
file2 := r.WriteFile("hello world2", "hello world2", t2)
|
|
|
|
|
|
|
|
// Set the --files-from equivalent
|
|
|
|
f, err := filter.NewFilter(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.AddFile("potato2"))
|
|
|
|
require.NoError(t, f.AddFile("notfound"))
|
|
|
|
|
|
|
|
// Monkey patch the active filter
|
|
|
|
oldFilter := filter.Active
|
2019-02-13 18:14:51 +01:00
|
|
|
oldNoTraverse := fs.Config.NoTraverse
|
2018-10-19 18:41:14 +02:00
|
|
|
filter.Active = f
|
2019-02-13 18:14:51 +01:00
|
|
|
fs.Config.NoTraverse = noTraverse
|
2018-10-19 18:41:14 +02:00
|
|
|
unpatch := func() {
|
|
|
|
filter.Active = oldFilter
|
2019-02-13 18:14:51 +01:00
|
|
|
fs.Config.NoTraverse = oldNoTraverse
|
2018-10-19 18:41:14 +02:00
|
|
|
}
|
|
|
|
defer unpatch()
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2018-10-19 18:41:14 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
unpatch()
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
}
|
2019-02-13 18:14:51 +01:00
|
|
|
func TestCopyWithFilesFrom(t *testing.T) { testCopyWithFilesFrom(t, false) }
|
|
|
|
func TestCopyWithFilesFromAndNoTraverse(t *testing.T) { testCopyWithFilesFrom(t, true) }
|
2018-10-19 18:41:14 +02:00
|
|
|
|
2018-06-03 10:21:25 +02:00
|
|
|
// Test copy empty directories
|
|
|
|
func TestCopyEmptyDirectories(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), r.Flocal, "sub dir2")
|
2018-06-03 10:21:25 +02:00
|
|
|
require.NoError(t, err)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-06-03 10:21:25 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = CopyDir(context.Background(), r.Fremote, r.Flocal, true)
|
2019-03-06 09:43:46 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"sub dir",
|
|
|
|
"sub dir2",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test move empty directories
|
|
|
|
func TestMoveEmptyDirectories(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), r.Flocal, "sub dir2")
|
2019-03-06 09:43:46 +01:00
|
|
|
require.NoError(t, err)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2019-03-06 09:43:46 +01:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = MoveDir(context.Background(), r.Fremote, r.Flocal, false, true)
|
2019-03-06 09:43:46 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"sub dir",
|
|
|
|
"sub dir2",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test sync empty directories
|
|
|
|
func TestSyncEmptyDirectories(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), r.Flocal, "sub dir2")
|
2019-03-06 09:43:46 +01:00
|
|
|
require.NoError(t, err)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2019-03-06 09:43:46 +01:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, true)
|
2018-06-03 10:21:25 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"sub dir",
|
|
|
|
"sub dir2",
|
|
|
|
},
|
2018-06-04 18:48:18 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2018-06-03 10:21:25 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
// Test a server side copy if possible, or the backup path if not
|
|
|
|
func TestServerSideCopy(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
FremoteCopy, _, finaliseCopy, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer finaliseCopy()
|
2017-10-29 13:23:10 +01:00
|
|
|
t.Logf("Server side copy (if possible) %v -> %v", r.Fremote, FremoteCopy)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = CopyDir(context.Background(), FremoteCopy, r.Fremote, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, FremoteCopy, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that if the local file doesn't exist when we copy it up,
|
|
|
|
// nothing happens to the remote file
|
|
|
|
func TestCopyAfterDelete(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), r.Flocal, "")
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err = CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the copy downloading a file
|
|
|
|
func TestCopyRedownload(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Flocal, r.Fremote, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-06-10 18:33:17 +02:00
|
|
|
// Test with combined precision of local and remote as we copied it there and back
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1}, nil, fs.GetModifyWindow(r.Flocal, r.Fremote))
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a file and sync it. Change the last modified date and resync.
|
|
|
|
// If we're only doing sync by size and checksum, we expect nothing to
|
|
|
|
// to be transferred on the second sync.
|
|
|
|
func TestSyncBasedOnCheckSum(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
fs.Config.CheckSum = true
|
|
|
|
defer func() { fs.Config.CheckSum = false }()
|
|
|
|
|
2019-06-29 03:17:18 +02:00
|
|
|
file1 := r.WriteFile("check sum", "-", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly one file.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Change last modified date only
|
2019-06-29 03:17:18 +02:00
|
|
|
file2 := r.WriteFile("check sum", "-", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred no files
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a file and sync it. Change the last modified date and the
|
|
|
|
// file contents but not the size. If we're only doing sync by size
|
|
|
|
// only, we expect nothing to to be transferred on the second sync.
|
|
|
|
func TestSyncSizeOnly(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
fs.Config.SizeOnly = true
|
|
|
|
defer func() { fs.Config.SizeOnly = false }()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("sizeonly", "potato", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly one file.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Update mtime, md5sum but not length of file
|
|
|
|
file2 := r.WriteFile("sizeonly", "POTATO", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred no files
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a file and sync it. Keep the last modified date but change
|
|
|
|
// the size. With --ignore-size we expect nothing to to be
|
|
|
|
// transferred on the second sync.
|
|
|
|
func TestSyncIgnoreSize(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
fs.Config.IgnoreSize = true
|
|
|
|
defer func() { fs.Config.IgnoreSize = false }()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("ignore-size", "contents", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly one file.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Update size but not date of file
|
|
|
|
file2 := r.WriteFile("ignore-size", "longer contents but same date", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred no files
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncIgnoreTimes(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "existing", "potato", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly 0 files because the
|
|
|
|
// files were identical.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers())
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
fs.Config.IgnoreTimes = true
|
|
|
|
defer func() { fs.Config.IgnoreTimes = false }()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly one file even though the
|
|
|
|
// files were identical.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncIgnoreExisting(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("existing", "potato", t1)
|
|
|
|
|
|
|
|
fs.Config.IgnoreExisting = true
|
|
|
|
defer func() { fs.Config.IgnoreExisting = false }()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Change everything
|
|
|
|
r.WriteFile("existing", "newpotatoes", t2)
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
// Items should not change
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:40:19 +01:00
|
|
|
func TestSyncIgnoreErrors(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
fs.Config.IgnoreErrors = true
|
|
|
|
defer func() {
|
|
|
|
fs.Config.IgnoreErrors = false
|
|
|
|
r.Finalise()
|
|
|
|
}()
|
|
|
|
file1 := r.WriteFile("a/potato2", "------------------------------------------------------------", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "b/potato", "SMALLER BUT SAME DATE", t2)
|
|
|
|
file3 := r.WriteBoth(context.Background(), "c/non empty space", "AhHa!", t2)
|
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "d"))
|
2018-03-13 00:40:19 +01:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Flocal,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2018-03-13 00:40:19 +01:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file2,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"b",
|
|
|
|
"c",
|
|
|
|
"d",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2018-03-13 00:40:19 +01:00
|
|
|
)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-03-21 12:24:13 +01:00
|
|
|
fs.CountError(errors.New("boom"))
|
2019-06-17 10:34:30 +02:00
|
|
|
assert.NoError(t, Sync(context.Background(), r.Fremote, r.Flocal, false))
|
2018-03-13 00:40:19 +01:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Flocal,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2018-03-13 00:40:19 +01:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2018-03-13 00:40:19 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
func TestSyncAfterChangingModtimeOnly(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-29 03:17:18 +02:00
|
|
|
file1 := r.WriteFile("empty space", "-", t2)
|
|
|
|
file2 := r.WriteObject(context.Background(), "empty space", "-", t1)
|
2016-07-12 20:40:41 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-02-16 00:09:44 +01:00
|
|
|
fs.Config.DryRun = true
|
|
|
|
defer func() { fs.Config.DryRun = false }()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2017-02-16 00:09:44 +01:00
|
|
|
|
|
|
|
fs.Config.DryRun = false
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2017-02-16 00:09:44 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 11:46:45 +02:00
|
|
|
func TestSyncAfterChangingModtimeOnlyWithNoUpdateModTime(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-12 11:46:45 +02:00
|
|
|
defer r.Finalise()
|
2016-12-31 16:19:26 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
if r.Fremote.Hashes().Count() == 0 {
|
2017-02-09 12:01:20 +01:00
|
|
|
t.Logf("Can't check this if no hashes supported")
|
2016-12-31 16:19:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-12 11:46:45 +02:00
|
|
|
fs.Config.NoUpdateModTime = true
|
|
|
|
defer func() {
|
|
|
|
fs.Config.NoUpdateModTime = false
|
|
|
|
}()
|
|
|
|
|
2019-06-29 03:17:18 +02:00
|
|
|
file1 := r.WriteFile("empty space", "-", t2)
|
|
|
|
file2 := r.WriteObject(context.Background(), "empty space", "-", t1)
|
2016-07-12 11:46:45 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-12 20:40:41 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-12 11:46:45 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-12 11:46:45 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 18:08:15 +01:00
|
|
|
func TestSyncDoesntUpdateModtime(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-11-28 18:08:15 +01:00
|
|
|
defer r.Finalise()
|
2018-06-03 20:45:34 +02:00
|
|
|
if fs.GetModifyWindow(r.Fremote) == fs.ModTimeNotSupported {
|
|
|
|
t.Skip("Can't run this test on fs which doesn't support mod time")
|
|
|
|
}
|
2016-11-28 18:08:15 +01:00
|
|
|
|
|
|
|
file1 := r.WriteFile("foo", "foo", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "foo", "bar", t1)
|
2016-11-28 18:08:15 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-11-28 18:08:15 +01:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-11-28 18:08:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-11-28 18:08:15 +01:00
|
|
|
|
|
|
|
// We should have transferred exactly one file, not set the mod time
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2016-11-28 18:08:15 +01:00
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
func TestSyncAfterAddingAFile(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-29 03:17:18 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-07-04 14:12:33 +02:00
|
|
|
file2 := r.WriteFile("potato", "------------------------------------------------------------", t3)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-12 20:40:41 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncAfterChangingFilesSizeOnly(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "potato", "------------------------------------------------------------", t3)
|
2016-07-04 14:12:33 +02:00
|
|
|
file2 := r.WriteFile("potato", "smaller but same date", t3)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync after changing a file's contents, changing modtime but length
|
|
|
|
// remaining the same
|
|
|
|
func TestSyncAfterChangingContentsOnly(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
var file1 fstest.Item
|
2017-10-29 13:23:10 +01:00
|
|
|
if r.Fremote.Precision() == fs.ModTimeNotSupported {
|
2016-07-04 14:12:33 +02:00
|
|
|
t.Logf("ModTimeNotSupported so forcing file to be a different size")
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 = r.WriteObject(context.Background(), "potato", "different size to make sure it syncs", t3)
|
2016-07-04 14:12:33 +02:00
|
|
|
} else {
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 = r.WriteObject(context.Background(), "potato", "smaller but same date", t3)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
file2 := r.WriteFile("potato", "SMALLER BUT SAME DATE", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync after removing a file and adding a file --dry-run
|
|
|
|
func TestSyncAfterRemovingAFileAndAddingAFileDryRun(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("potato2", "------------------------------------------------------------", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "potato", "SMALLER BUT SAME DATE", t2)
|
2019-06-29 03:17:18 +02:00
|
|
|
file3 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
fs.Config.DryRun = true
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
fs.Config.DryRun = false
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file3, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file3, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync after removing a file and adding a file
|
|
|
|
func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("potato2", "------------------------------------------------------------", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "potato", "SMALLER BUT SAME DATE", t2)
|
2019-06-29 03:17:18 +02:00
|
|
|
file3 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file3)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2017-01-25 20:59:53 +01:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file3)
|
2017-01-25 20:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync after removing a file and adding a file
|
|
|
|
func TestSyncAfterRemovingAFileAndAddingAFileSubDir(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2017-01-25 20:59:53 +01:00
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("a/potato2", "------------------------------------------------------------", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "b/potato", "SMALLER BUT SAME DATE", t2)
|
|
|
|
file3 := r.WriteBoth(context.Background(), "c/non empty space", "AhHa!", t2)
|
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "d"))
|
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "d/e"))
|
2017-08-09 22:06:39 +02:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Flocal,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Fremote,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file2,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"b",
|
|
|
|
"c",
|
|
|
|
"d",
|
|
|
|
"d/e",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
2017-01-25 20:59:53 +01:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-08-09 22:06:39 +02:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Flocal,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Fremote,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync after removing a file and adding a file with IO Errors
|
2017-08-09 22:06:39 +02:00
|
|
|
func TestSyncAfterRemovingAFileAndAddingAFileSubDirWithErrors(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2017-08-09 22:06:39 +02:00
|
|
|
file1 := r.WriteFile("a/potato2", "------------------------------------------------------------", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "b/potato", "SMALLER BUT SAME DATE", t2)
|
|
|
|
file3 := r.WriteBoth(context.Background(), "c/non empty space", "AhHa!", t2)
|
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "d"))
|
2017-08-09 22:06:39 +02:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Flocal,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Fremote,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file2,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"b",
|
|
|
|
"c",
|
|
|
|
"d",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-03-21 12:24:13 +01:00
|
|
|
fs.CountError(errors.New("boom"))
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
assert.Equal(t, fs.ErrorNotDeleting, err)
|
2017-08-09 22:06:39 +02:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Flocal,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"c",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 13:23:10 +01:00
|
|
|
r.Fremote,
|
2017-08-09 22:06:39 +02:00
|
|
|
[]fstest.Item{
|
|
|
|
file1,
|
|
|
|
file2,
|
|
|
|
file3,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"a",
|
|
|
|
"b",
|
|
|
|
"c",
|
|
|
|
"d",
|
|
|
|
},
|
2018-06-03 20:45:34 +02:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-08-09 22:06:39 +02:00
|
|
|
)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 20:35:14 +01:00
|
|
|
// Sync test delete after
|
|
|
|
func TestSyncDeleteAfter(t *testing.T) {
|
2016-07-04 14:12:33 +02:00
|
|
|
// This is the default so we've checked this already
|
|
|
|
// check it is the default
|
2017-01-25 20:35:14 +01:00
|
|
|
require.Equal(t, fs.Config.DeleteMode, fs.DeleteModeAfter, "Didn't default to --delete-after")
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 20:35:14 +01:00
|
|
|
// Sync test delete during
|
|
|
|
func TestSyncDeleteDuring(t *testing.T) {
|
|
|
|
fs.Config.DeleteMode = fs.DeleteModeDuring
|
2016-07-04 14:12:33 +02:00
|
|
|
defer func() {
|
2017-01-25 20:35:14 +01:00
|
|
|
fs.Config.DeleteMode = fs.DeleteModeDefault
|
2016-07-04 14:12:33 +02:00
|
|
|
}()
|
|
|
|
|
|
|
|
TestSyncAfterRemovingAFileAndAddingAFile(t)
|
|
|
|
}
|
|
|
|
|
2017-01-25 20:35:14 +01:00
|
|
|
// Sync test delete before
|
|
|
|
func TestSyncDeleteBefore(t *testing.T) {
|
|
|
|
fs.Config.DeleteMode = fs.DeleteModeBefore
|
2016-07-04 14:12:33 +02:00
|
|
|
defer func() {
|
2017-01-25 20:35:14 +01:00
|
|
|
fs.Config.DeleteMode = fs.DeleteModeDefault
|
2016-07-04 14:12:33 +02:00
|
|
|
}()
|
|
|
|
|
|
|
|
TestSyncAfterRemovingAFileAndAddingAFile(t)
|
|
|
|
}
|
|
|
|
|
2017-02-22 14:17:38 +01:00
|
|
|
// Copy test delete before - shouldn't delete anything
|
|
|
|
func TestCopyDeleteBefore(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2017-02-22 14:17:38 +01:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.DeleteMode = fs.DeleteModeBefore
|
|
|
|
defer func() {
|
|
|
|
fs.Config.DeleteMode = fs.DeleteModeDefault
|
|
|
|
}()
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "potato", "hopefully not deleted", t1)
|
2017-02-22 14:17:38 +01:00
|
|
|
file2 := r.WriteFile("potato2", "hopefully copied in", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2017-02-22 14:17:38 +01:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := CopyDir(context.Background(), r.Fremote, r.Flocal, false)
|
2017-02-22 14:17:38 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2017-02-22 14:17:38 +01:00
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
// Test with exclude
|
|
|
|
func TestSyncWithExclude(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 03:17:18 +02:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-07-04 14:12:33 +02:00
|
|
|
file3 := r.WriteFile("enormous", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MaxSize = 40
|
2016-07-04 14:12:33 +02:00
|
|
|
defer func() {
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MaxSize = -1
|
2016-07-04 14:12:33 +02:00
|
|
|
}()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file1)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Now sync the other way round and check enormous doesn't get
|
|
|
|
// deleted as it is excluded from the sync
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Flocal, r.Fremote, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2, file1, file3)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test with exclude and delete excluded
|
|
|
|
func TestSyncWithExcludeAndDeleteExcluded(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1) // 60 bytes
|
2019-06-29 03:17:18 +02:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3 := r.WriteBoth(context.Background(), "enormous", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MaxSize = 40
|
|
|
|
filter.Active.Opt.DeleteExcluded = true
|
2016-07-04 14:12:33 +02:00
|
|
|
defer func() {
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MaxSize = -1
|
|
|
|
filter.Active.Opt.DeleteExcluded = false
|
2016-07-04 14:12:33 +02:00
|
|
|
}()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Check sync the other way round to make sure enormous gets
|
|
|
|
// deleted even though it is excluded
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Flocal, r.Fremote, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test with UpdateOlder set
|
|
|
|
func TestSyncWithUpdateOlder(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-04 14:12:33 +02:00
|
|
|
defer r.Finalise()
|
2018-06-03 20:45:34 +02:00
|
|
|
if fs.GetModifyWindow(r.Fremote) == fs.ModTimeNotSupported {
|
|
|
|
t.Skip("Can't run this test on fs which doesn't support mod time")
|
|
|
|
}
|
2016-07-04 14:12:33 +02:00
|
|
|
t2plus := t2.Add(time.Second / 2)
|
|
|
|
t2minus := t2.Add(time.Second / 2)
|
|
|
|
oneF := r.WriteFile("one", "one", t1)
|
|
|
|
twoF := r.WriteFile("two", "two", t3)
|
|
|
|
threeF := r.WriteFile("three", "three", t2)
|
|
|
|
fourF := r.WriteFile("four", "four", t2)
|
|
|
|
fiveF := r.WriteFile("five", "five", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, oneF, twoF, threeF, fourF, fiveF)
|
2019-06-17 10:34:30 +02:00
|
|
|
oneO := r.WriteObject(context.Background(), "one", "ONE", t2)
|
|
|
|
twoO := r.WriteObject(context.Background(), "two", "TWO", t2)
|
|
|
|
threeO := r.WriteObject(context.Background(), "three", "THREE", t2plus)
|
|
|
|
fourO := r.WriteObject(context.Background(), "four", "FOURFOUR", t2minus)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, oneO, twoO, threeO, fourO)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
fs.Config.UpdateOlder = true
|
|
|
|
oldModifyWindow := fs.Config.ModifyWindow
|
|
|
|
fs.Config.ModifyWindow = fs.ModTimeNotSupported
|
|
|
|
defer func() {
|
|
|
|
fs.Config.UpdateOlder = false
|
|
|
|
fs.Config.ModifyWindow = oldModifyWindow
|
|
|
|
}()
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, oneO, twoF, threeO, fourF, fiveF)
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2016-12-18 11:03:56 +01:00
|
|
|
// Test with TrackRenames set
|
|
|
|
func TestSyncWithTrackRenames(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-12-18 11:03:56 +01:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.TrackRenames = true
|
|
|
|
defer func() {
|
|
|
|
fs.Config.TrackRenames = false
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
2018-01-18 21:27:52 +01:00
|
|
|
haveHash := r.Fremote.Hashes().Overlap(r.Flocal.Hashes()).GetOne() != hash.None
|
2018-01-12 17:30:54 +01:00
|
|
|
canTrackRenames := haveHash && operations.CanServerSideMove(r.Fremote)
|
2017-01-03 18:35:12 +01:00
|
|
|
t.Logf("Can track renames: %v", canTrackRenames)
|
|
|
|
|
2016-12-18 11:03:56 +01:00
|
|
|
f1 := r.WriteFile("potato", "Potato Content", t1)
|
|
|
|
f2 := r.WriteFile("yam", "Yam Content", t2)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
require.NoError(t, Sync(context.Background(), r.Fremote, r.Flocal, false))
|
2016-12-18 11:03:56 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, f1, f2)
|
|
|
|
fstest.CheckItems(t, r.Flocal, f1, f2)
|
2016-12-18 11:03:56 +01:00
|
|
|
|
|
|
|
// Now rename locally.
|
|
|
|
f2 = r.RenameFile(f2, "yaml")
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
require.NoError(t, Sync(context.Background(), r.Fremote, r.Flocal, false))
|
2016-12-18 11:03:56 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, f1, f2)
|
2016-12-18 11:03:56 +01:00
|
|
|
|
2017-01-03 18:35:12 +01:00
|
|
|
if canTrackRenames {
|
2019-06-15 11:53:36 +02:00
|
|
|
if r.Fremote.Features().Move == nil || r.Fremote.Name() == "TestUnion" { // union remote can Move but returns CantMove error
|
2019-05-12 10:50:20 +02:00
|
|
|
// If no server side Move, we are falling back to Copy + Delete
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers()) // 1 copy
|
|
|
|
assert.Equal(t, int64(4), accounting.GlobalStats().GetChecks()) // 2 file checks + 1 move + 1 delete
|
2019-05-12 10:50:20 +02:00
|
|
|
} else {
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers()) // 0 copy
|
|
|
|
assert.Equal(t, int64(3), accounting.GlobalStats().GetChecks()) // 2 file checks + 1 move
|
2019-05-12 10:50:20 +02:00
|
|
|
}
|
2017-01-03 18:35:12 +01:00
|
|
|
} else {
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(2), accounting.GlobalStats().GetChecks()) // 2 file checks
|
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers()) // 0 copy
|
2017-01-03 18:35:12 +01:00
|
|
|
}
|
2016-12-18 11:03:56 +01:00
|
|
|
}
|
|
|
|
|
2016-07-04 14:12:33 +02:00
|
|
|
// Test a server side move if possible, or the backup path if not
|
2017-11-27 12:42:02 +01:00
|
|
|
func testServerSideMove(t *testing.T, r *fstest.Run, withFilter, testDeleteEmptyDirs bool) {
|
2017-10-29 13:23:10 +01:00
|
|
|
FremoteMove, _, finaliseMove, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
2017-08-04 18:08:16 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer finaliseMove()
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 03:17:18 +02:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3u := r.WriteBoth(context.Background(), "potato3", "------------------------------------------------------------ UPDATED", t2)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-11-27 12:42:02 +01:00
|
|
|
if testDeleteEmptyDirs {
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), r.Fremote, "tomatoDir")
|
2017-11-27 12:42:02 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file1, file3u)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
t.Logf("Server side move (if possible) %v -> %v", r.Fremote, FremoteMove)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Write just one file in the new remote
|
2019-06-29 03:17:18 +02:00
|
|
|
r.WriteObjectTo(context.Background(), FremoteMove, "empty space", "-", t2, false)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3 := r.WriteObjectTo(context.Background(), FremoteMove, "potato3", "------------------------------------------------------------", t1, false)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, FremoteMove, file2, file3)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
|
|
|
// Do server side move
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = MoveDir(context.Background(), FremoteMove, r.Fremote, testDeleteEmptyDirs, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2016-10-03 20:58:44 +02:00
|
|
|
if withFilter {
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-10-03 20:58:44 +02:00
|
|
|
} else {
|
2017-11-23 06:22:01 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote)
|
2016-10-03 20:58:44 +02:00
|
|
|
}
|
2017-11-27 12:42:02 +01:00
|
|
|
|
|
|
|
if testDeleteEmptyDirs {
|
2018-06-03 20:45:34 +02:00
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, nil, []string{}, fs.GetModifyWindow(r.Fremote))
|
2017-11-27 12:42:02 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, FremoteMove, file2, file1, file3u)
|
2016-07-04 14:12:33 +02:00
|
|
|
|
2017-08-04 18:08:16 +02:00
|
|
|
// Create a new empty remote for stuff to be moved into
|
2017-10-29 13:23:10 +01:00
|
|
|
FremoteMove2, _, finaliseMove2, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
2017-08-04 18:08:16 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer finaliseMove2()
|
2016-07-11 12:36:46 +02:00
|
|
|
|
2017-11-27 12:42:02 +01:00
|
|
|
if testDeleteEmptyDirs {
|
2019-06-17 10:34:30 +02:00
|
|
|
err := operations.Mkdir(context.Background(), FremoteMove, "tomatoDir")
|
2017-11-27 12:42:02 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2017-08-04 18:08:16 +02:00
|
|
|
// Move it back to a new empty remote, dst does not exist this time
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = MoveDir(context.Background(), FremoteMove2, FremoteMove, testDeleteEmptyDirs, false)
|
2016-07-04 14:12:33 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2016-07-11 12:36:46 +02:00
|
|
|
if withFilter {
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, FremoteMove2, file1, file3u)
|
|
|
|
fstest.CheckItems(t, FremoteMove, file2)
|
2016-07-11 12:36:46 +02:00
|
|
|
} else {
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, FremoteMove2, file2, file1, file3u)
|
2017-11-23 06:22:01 +01:00
|
|
|
fstest.CheckItems(t, FremoteMove)
|
2016-07-11 12:36:46 +02:00
|
|
|
}
|
2017-11-27 12:42:02 +01:00
|
|
|
|
|
|
|
if testDeleteEmptyDirs {
|
2018-06-03 20:45:34 +02:00
|
|
|
fstest.CheckListingWithPrecision(t, FremoteMove, nil, []string{}, fs.GetModifyWindow(r.Fremote))
|
2017-11-27 12:42:02 +01:00
|
|
|
}
|
2016-07-11 12:36:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 07:43:58 +02:00
|
|
|
// Test move
|
|
|
|
func TestMoveWithDeleteEmptySrcDirs(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
|
|
|
file2 := r.WriteFile("nested/sub dir/file", "nested", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-07-17 07:43:58 +02:00
|
|
|
|
|
|
|
// run move with --delete-empty-src-dirs
|
2019-06-17 10:34:30 +02:00
|
|
|
err := MoveDir(context.Background(), r.Fremote, r.Flocal, true, false)
|
2018-07-17 07:43:58 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Flocal,
|
|
|
|
nil,
|
|
|
|
[]string{},
|
|
|
|
fs.GetModifyWindow(r.Flocal),
|
|
|
|
)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMoveWithoutDeleteEmptySrcDirs(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
|
|
|
file2 := r.WriteFile("nested/sub dir/file", "nested", t1)
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-07-17 07:43:58 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := MoveDir(context.Background(), r.Fremote, r.Flocal, false, false)
|
2018-07-17 07:43:58 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Flocal,
|
|
|
|
nil,
|
|
|
|
[]string{
|
|
|
|
"sub dir",
|
|
|
|
"nested",
|
|
|
|
"nested/sub dir",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Flocal),
|
|
|
|
)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
}
|
|
|
|
|
2016-07-11 12:36:46 +02:00
|
|
|
// Test a server side move if possible, or the backup path if not
|
|
|
|
func TestServerSideMove(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-11 12:36:46 +02:00
|
|
|
defer r.Finalise()
|
2017-11-27 12:42:02 +01:00
|
|
|
testServerSideMove(t, r, false, false)
|
2016-07-11 12:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a server side move if possible, or the backup path if not
|
|
|
|
func TestServerSideMoveWithFilter(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-11 12:36:46 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MinSize = 40
|
2016-07-11 12:36:46 +02:00
|
|
|
defer func() {
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MinSize = -1
|
2016-07-11 12:36:46 +02:00
|
|
|
}()
|
|
|
|
|
2017-11-27 12:42:02 +01:00
|
|
|
testServerSideMove(t, r, true, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a server side move if possible
|
|
|
|
func TestServerSideMoveDeleteEmptySourceDirs(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
testServerSideMove(t, r, false, true)
|
2016-07-11 12:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a server side move with overlap
|
|
|
|
func TestServerSideMoveOverlap(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2016-07-11 12:36:46 +02:00
|
|
|
defer r.Finalise()
|
2016-10-22 18:53:52 +02:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
if r.Fremote.Features().DirMove != nil {
|
2016-10-22 18:53:52 +02:00
|
|
|
t.Skip("Skipping test as remote supports DirMove")
|
|
|
|
}
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
subRemoteName := r.FremoteName + "/rclone-move-test"
|
|
|
|
FremoteMove, err := fs.NewFs(subRemoteName)
|
2016-07-11 12:36:46 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-07-11 12:36:46 +02:00
|
|
|
|
|
|
|
// Subdir move with no filters should return ErrorCantMoveOverlapping
|
2019-06-17 10:34:30 +02:00
|
|
|
err = MoveDir(context.Background(), FremoteMove, r.Fremote, false, false)
|
2019-02-14 13:06:26 +01:00
|
|
|
assert.EqualError(t, err, fs.ErrorOverlapping.Error())
|
2016-07-11 12:36:46 +02:00
|
|
|
|
|
|
|
// Now try with a filter which should also fail with ErrorCantMoveOverlapping
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MinSize = 40
|
2016-07-11 12:36:46 +02:00
|
|
|
defer func() {
|
2018-01-12 17:30:54 +01:00
|
|
|
filter.Active.Opt.MinSize = -1
|
2016-07-11 12:36:46 +02:00
|
|
|
}()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = MoveDir(context.Background(), FremoteMove, r.Fremote, false, false)
|
2019-02-27 18:13:13 +01:00
|
|
|
assert.EqualError(t, err, fs.ErrorOverlapping.Error())
|
2019-02-14 13:06:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a sync with overlap
|
|
|
|
func TestSyncOverlap(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
subRemoteName := r.FremoteName + "/rclone-sync-test"
|
|
|
|
FremoteSync, err := fs.NewFs(subRemoteName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
checkErr := func(err error) {
|
2019-02-28 12:39:32 +01:00
|
|
|
require.Error(t, err)
|
2019-02-14 13:06:26 +01:00
|
|
|
assert.True(t, fserrors.IsFatalError(err))
|
2019-02-28 12:39:32 +01:00
|
|
|
assert.Equal(t, fs.ErrorOverlapping.Error(), err.Error())
|
2019-02-14 13:06:26 +01:00
|
|
|
}
|
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
checkErr(Sync(context.Background(), FremoteSync, r.Fremote, false))
|
|
|
|
checkErr(Sync(context.Background(), r.Fremote, FremoteSync, false))
|
|
|
|
checkErr(Sync(context.Background(), r.Fremote, r.Fremote, false))
|
|
|
|
checkErr(Sync(context.Background(), FremoteSync, FremoteSync, false))
|
2016-07-04 14:12:33 +02:00
|
|
|
}
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2019-07-08 03:02:53 +02:00
|
|
|
// Test with CompareDest set
|
|
|
|
func TestSyncCompareDest(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.CompareDest = r.FremoteName + "/CompareDest"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.CompareDest = ""
|
|
|
|
}()
|
|
|
|
|
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check empty dest, empty compare
|
|
|
|
file1 := r.WriteFile("one", "one", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1dst := file1
|
|
|
|
file1dst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
|
|
|
|
// check old dest, empty compare
|
|
|
|
file1b := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1b)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1bdst := file1b
|
|
|
|
file1bdst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1bdst)
|
|
|
|
|
|
|
|
// check old dest, new compare
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "CompareDest/one", "onet2", t2)
|
|
|
|
file1c := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
|
|
|
|
// check empty dest, new compare
|
|
|
|
file4 := r.WriteObject(context.Background(), "CompareDest/two", "two", t2)
|
|
|
|
file5 := r.WriteFile("two", "two", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
|
|
|
|
// check new dest, new compare
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
|
|
|
|
// check empty dest, old compare
|
|
|
|
file5b := r.WriteFile("two", "twot3", t3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5b)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file5bdst := file5b
|
|
|
|
file5bdst.Path = "dst/two"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4, file5bdst)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with CopyDest set
|
|
|
|
func TestSyncCopyDest(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
if r.Fremote.Features().Copy == nil {
|
|
|
|
t.Skip("Skipping test as remote does not support server side copy")
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.Config.CopyDest = r.FremoteName + "/CopyDest"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.CopyDest = ""
|
|
|
|
}()
|
|
|
|
|
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check empty dest, empty copy
|
|
|
|
file1 := r.WriteFile("one", "one", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1dst := file1
|
|
|
|
file1dst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
|
|
|
|
// check old dest, empty copy
|
|
|
|
file1b := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1b)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1bdst := file1b
|
|
|
|
file1bdst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1bdst)
|
|
|
|
|
|
|
|
// check old dest, new copy, backup-dir
|
|
|
|
|
|
|
|
fs.Config.BackupDir = r.FremoteName + "/BackupDir"
|
|
|
|
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "CopyDest/one", "onet2", t2)
|
|
|
|
file1c := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file2dst := file2
|
|
|
|
file2dst.Path = "dst/one"
|
|
|
|
file3.Path = "BackupDir/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3)
|
|
|
|
fs.Config.BackupDir = ""
|
|
|
|
|
|
|
|
// check empty dest, new copy
|
|
|
|
file4 := r.WriteObject(context.Background(), "CopyDest/two", "two", t2)
|
|
|
|
file5 := r.WriteFile("two", "two", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file4dst := file4
|
|
|
|
file4dst.Path = "dst/two"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
|
|
|
|
|
|
|
// check new dest, new copy
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
|
|
|
|
|
|
|
// check empty dest, old copy
|
|
|
|
file6 := r.WriteObject(context.Background(), "CopyDest/three", "three", t2)
|
|
|
|
file7 := r.WriteFile("three", "threet3", t3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5, file7)
|
|
|
|
|
|
|
|
accounting.Stats.ResetCounters()
|
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file7dst := file7
|
|
|
|
file7dst.Path = "dst/three"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6, file7dst)
|
|
|
|
}
|
|
|
|
|
2017-01-10 22:47:03 +01:00
|
|
|
// Test with BackupDir set
|
2019-03-10 17:50:28 +01:00
|
|
|
func testSyncBackupDir(t *testing.T, suffix string, suffixKeepExtension bool) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2017-01-10 22:47:03 +01:00
|
|
|
defer r.Finalise()
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
if !operations.CanServerSideMove(r.Fremote) {
|
2017-01-10 22:47:03 +01:00
|
|
|
t.Skip("Skipping test as remote does not support server side move")
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fs.Config.BackupDir = r.FremoteName + "/backup"
|
2017-01-19 18:26:29 +01:00
|
|
|
fs.Config.Suffix = suffix
|
2019-03-10 17:50:28 +01:00
|
|
|
fs.Config.SuffixKeepExtension = suffixKeepExtension
|
2017-01-10 22:47:03 +01:00
|
|
|
defer func() {
|
|
|
|
fs.Config.BackupDir = ""
|
2017-01-19 18:26:29 +01:00
|
|
|
fs.Config.Suffix = ""
|
2019-03-10 17:50:28 +01:00
|
|
|
fs.Config.SuffixKeepExtension = false
|
2017-01-10 22:47:03 +01:00
|
|
|
}()
|
|
|
|
|
2017-01-19 18:26:29 +01:00
|
|
|
// Make the setup so we have one, two, three in the dest
|
|
|
|
// and one (different), two (same) in the source
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "dst/two", "two", t1)
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/three.txt", "three", t1)
|
2017-01-19 18:26:29 +01:00
|
|
|
file2a := r.WriteFile("two", "two", t1)
|
|
|
|
file1a := r.WriteFile("one", "oneA", t2)
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1a, file2a)
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
2017-01-10 22:47:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
2017-01-10 22:47:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-01-19 18:26:29 +01:00
|
|
|
// one should be moved to the backup dir and the new one installed
|
|
|
|
file1.Path = "backup/one" + suffix
|
2017-01-10 22:47:03 +01:00
|
|
|
file1a.Path = "dst/one"
|
2017-01-19 18:26:29 +01:00
|
|
|
// two should be unchanged
|
|
|
|
// three should be moved to the backup dir
|
2019-03-10 17:50:28 +01:00
|
|
|
if suffixKeepExtension {
|
|
|
|
file3.Path = "backup/three" + suffix + ".txt"
|
|
|
|
} else {
|
|
|
|
file3.Path = "backup/three.txt" + suffix
|
|
|
|
}
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3, file1a)
|
2017-01-10 22:47:03 +01:00
|
|
|
|
2017-01-19 18:26:29 +01:00
|
|
|
// Now check what happens if we do it again
|
|
|
|
// Restore a different three and update one in the source
|
2019-06-17 10:34:30 +02:00
|
|
|
file3a := r.WriteObject(context.Background(), "dst/three.txt", "threeA", t2)
|
2017-01-19 18:26:29 +01:00
|
|
|
file1b := r.WriteFile("one", "oneBB", t3)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3, file1a, file3a)
|
2017-01-19 18:26:29 +01:00
|
|
|
|
|
|
|
// This should delete three and overwrite one again, checking
|
|
|
|
// the files got overwritten correctly in backup-dir
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), fdst, r.Flocal, false)
|
2017-01-19 18:26:29 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// one should be moved to the backup dir and the new one installed
|
|
|
|
file1a.Path = "backup/one" + suffix
|
|
|
|
file1b.Path = "dst/one"
|
|
|
|
// two should be unchanged
|
|
|
|
// three should be moved to the backup dir
|
2019-03-10 17:50:28 +01:00
|
|
|
if suffixKeepExtension {
|
|
|
|
file3a.Path = "backup/three" + suffix + ".txt"
|
|
|
|
} else {
|
|
|
|
file3a.Path = "backup/three.txt" + suffix
|
|
|
|
}
|
2017-01-19 18:26:29 +01:00
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1b, file2, file3a, file1a)
|
2017-01-10 22:47:03 +01:00
|
|
|
}
|
2019-03-10 17:50:28 +01:00
|
|
|
func TestSyncBackupDir(t *testing.T) { testSyncBackupDir(t, "", false) }
|
|
|
|
func TestSyncBackupDirWithSuffix(t *testing.T) { testSyncBackupDir(t, ".bak", false) }
|
|
|
|
func TestSyncBackupDirWithSuffixKeepExtension(t *testing.T) { testSyncBackupDir(t, "-2019-01-01", true) }
|
2017-09-08 17:19:41 +02:00
|
|
|
|
2019-06-23 05:52:09 +02:00
|
|
|
// Test with Suffix set
|
|
|
|
func testSyncSuffix(t *testing.T, suffix string, suffixKeepExtension bool) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
if !operations.CanServerSideMove(r.Fremote) {
|
|
|
|
t.Skip("Skipping test as remote does not support server side move")
|
|
|
|
}
|
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
|
|
|
|
|
|
|
fs.Config.Suffix = suffix
|
|
|
|
fs.Config.SuffixKeepExtension = suffixKeepExtension
|
|
|
|
defer func() {
|
|
|
|
fs.Config.BackupDir = ""
|
|
|
|
fs.Config.Suffix = ""
|
|
|
|
fs.Config.SuffixKeepExtension = false
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Make the setup so we have one, two, three in the dest
|
|
|
|
// and one (different), two (same) in the source
|
|
|
|
file1 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "dst/two", "two", t1)
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/three.txt", "three", t1)
|
|
|
|
file2a := r.WriteFile("two", "two", t1)
|
|
|
|
file1a := r.WriteFile("one", "oneA", t2)
|
|
|
|
file3a := r.WriteFile("three.txt", "threeA", t1)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1a, file2a, file3a)
|
|
|
|
|
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-23 05:52:09 +02:00
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "one", "one")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "two", "two")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "three.txt", "three.txt")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// one should be moved to the backup dir and the new one installed
|
|
|
|
file1.Path = "dst/one" + suffix
|
|
|
|
file1a.Path = "dst/one"
|
|
|
|
// two should be unchanged
|
|
|
|
// three should be moved to the backup dir
|
|
|
|
if suffixKeepExtension {
|
|
|
|
file3.Path = "dst/three" + suffix + ".txt"
|
|
|
|
} else {
|
|
|
|
file3.Path = "dst/three.txt" + suffix
|
|
|
|
}
|
|
|
|
file3a.Path = "dst/three.txt"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3, file1a, file3a)
|
|
|
|
|
|
|
|
// Now check what happens if we do it again
|
|
|
|
// Restore a different three and update one in the source
|
2019-07-03 18:36:22 +02:00
|
|
|
file3b := r.WriteFile("three.txt", "threeBDifferentSize", t3)
|
2019-06-23 05:52:09 +02:00
|
|
|
file1b := r.WriteFile("one", "oneBB", t3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3, file1a, file3a)
|
|
|
|
|
|
|
|
// This should delete three and overwrite one again, checking
|
|
|
|
// the files got overwritten correctly in backup-dir
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-23 05:52:09 +02:00
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "one", "one")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "two", "two")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, "three.txt", "three.txt")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// one should be moved to the backup dir and the new one installed
|
|
|
|
file1a.Path = "dst/one" + suffix
|
|
|
|
file1b.Path = "dst/one"
|
|
|
|
// two should be unchanged
|
|
|
|
// three should be moved to the backup dir
|
|
|
|
if suffixKeepExtension {
|
|
|
|
file3a.Path = "dst/three" + suffix + ".txt"
|
|
|
|
} else {
|
|
|
|
file3a.Path = "dst/three.txt" + suffix
|
|
|
|
}
|
|
|
|
file3b.Path = "dst/three.txt"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1b, file3b, file2, file3a, file1a)
|
|
|
|
}
|
|
|
|
func TestSyncSuffix(t *testing.T) { testSyncSuffix(t, ".bak", false) }
|
|
|
|
func TestSyncSuffixKeepExtension(t *testing.T) { testSyncSuffix(t, "-2019-01-01", true) }
|
|
|
|
|
2017-09-08 17:19:41 +02:00
|
|
|
// Check we can sync two files with differing UTF-8 representations
|
|
|
|
func TestSyncUTFNorm(t *testing.T) {
|
2017-09-17 15:05:33 +02:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
t.Skip("Can't test UTF normalization on OS X")
|
|
|
|
}
|
|
|
|
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2017-09-08 17:19:41 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
// Two strings with different unicode normalization (from OS X)
|
|
|
|
Encoding1 := "Testêé"
|
|
|
|
Encoding2 := "Testêé"
|
|
|
|
assert.NotEqual(t, Encoding1, Encoding2)
|
|
|
|
assert.Equal(t, norm.NFC.String(Encoding1), norm.NFC.String(Encoding2))
|
|
|
|
|
|
|
|
file1 := r.WriteFile(Encoding1, "This is a test", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2017-09-08 17:19:41 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), Encoding2, "This is a old test", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2017-09-08 17:19:41 +02:00
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2017-09-08 17:19:41 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We should have transferred exactly one file, but kept the
|
|
|
|
// normalized state of the file.
|
2019-07-18 12:13:54 +02:00
|
|
|
assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2017-09-08 17:19:41 +02:00
|
|
|
file1.Path = file2.Path
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2017-09-08 17:19:41 +02:00
|
|
|
}
|
2017-09-02 10:29:01 +02:00
|
|
|
|
|
|
|
// Test --immutable
|
|
|
|
func TestSyncImmutable(t *testing.T) {
|
2017-10-29 13:23:10 +01:00
|
|
|
r := fstest.NewRun(t)
|
2017-09-02 10:29:01 +02:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.Immutable = true
|
|
|
|
defer func() { fs.Config.Immutable = false }()
|
|
|
|
|
|
|
|
// Create file on source
|
|
|
|
file1 := r.WriteFile("existing", "potato", t1)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote)
|
2017-09-02 10:29:01 +02:00
|
|
|
|
|
|
|
// Should succeed
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2017-09-02 10:29:01 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2017-09-02 10:29:01 +02:00
|
|
|
|
|
|
|
// Modify file data and timestamp on source
|
2017-09-27 17:28:20 +02:00
|
|
|
file2 := r.WriteFile("existing", "tomatoes", t2)
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2017-09-02 10:29:01 +02:00
|
|
|
|
|
|
|
// Should fail with ErrorImmutableModified and not modify local or remote files
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err = Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2017-09-02 10:29:01 +02:00
|
|
|
assert.EqualError(t, err, fs.ErrorImmutableModified.Error())
|
2017-10-29 13:23:10 +01:00
|
|
|
fstest.CheckItems(t, r.Flocal, file2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2017-09-02 10:29:01 +02:00
|
|
|
}
|
2018-04-24 10:48:35 +02:00
|
|
|
|
2019-06-03 22:12:10 +02:00
|
|
|
// Test --ignore-case-sync
|
|
|
|
func TestSyncIgnoreCase(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
// Only test if filesystems are case sensitive
|
|
|
|
if r.Fremote.Features().CaseInsensitive || r.Flocal.Features().CaseInsensitive {
|
|
|
|
t.Skip("Skipping test as local or remote are case-insensitive")
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.Config.IgnoreCaseSync = true
|
|
|
|
defer func() { fs.Config.IgnoreCaseSync = false }()
|
|
|
|
|
|
|
|
// Create files with different filename casing
|
|
|
|
file1 := r.WriteFile("existing", "potato", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2019-06-17 10:34:30 +02:00
|
|
|
file2 := r.WriteObject(context.Background(), "EXISTING", "potato", t1)
|
2019-06-03 22:12:10 +02:00
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
|
|
|
|
|
|
|
// Should not copy files that are differently-cased but otherwise identical
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2019-06-03 22:12:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
|
|
|
}
|
|
|
|
|
2018-04-24 10:48:35 +02:00
|
|
|
// Test that aborting on max upload works
|
|
|
|
func TestAbort(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
if r.Fremote.Name() != "local" {
|
|
|
|
t.Skip("This test only runs on local")
|
|
|
|
}
|
|
|
|
|
|
|
|
oldMaxTransfer := fs.Config.MaxTransfer
|
|
|
|
oldTransfers := fs.Config.Transfers
|
|
|
|
oldCheckers := fs.Config.Checkers
|
|
|
|
fs.Config.MaxTransfer = 3 * 1024
|
|
|
|
fs.Config.Transfers = 1
|
|
|
|
fs.Config.Checkers = 1
|
|
|
|
defer func() {
|
|
|
|
fs.Config.MaxTransfer = oldMaxTransfer
|
|
|
|
fs.Config.Transfers = oldTransfers
|
|
|
|
fs.Config.Checkers = oldCheckers
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Create file on source
|
|
|
|
file1 := r.WriteFile("file1", string(make([]byte, 5*1024)), t1)
|
|
|
|
file2 := r.WriteFile("file2", string(make([]byte, 2*1024)), t1)
|
|
|
|
file3 := r.WriteFile("file3", string(make([]byte, 3*1024)), t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Fremote)
|
|
|
|
|
2019-07-18 12:13:54 +02:00
|
|
|
accounting.GlobalStats().ResetCounters()
|
2018-04-24 10:48:35 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
err := Sync(context.Background(), r.Fremote, r.Flocal, false)
|
2018-04-24 10:48:35 +02:00
|
|
|
assert.Equal(t, accounting.ErrorMaxTransferLimitReached, err)
|
|
|
|
}
|