"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
bisync: fix rc ignoring legacy backupdir1/2 and invalid values
nielash0891ce30606c
diff --git a/cmd/bisync/rc.go b/cmd/bisync/rc.goindex 8de454618..a6139a230 100644--- a/cmd/bisync/rc.go+++ b/cmd/bisync/rc.go@@ -82,54 +82,52 @@ func rcBisync(ctx context.Context, in rc.Params) (out rc.Params, err error) {}if opt.Resync, err = in.GetBool("resync"); rc.NotErrParamNotFound(err) {- fs.Debugf("resync", "optional parameter is missing. using default value: %v", opt.Resync)+ return nil, err}if opt.CheckAccess, err = in.GetBool("checkAccess"); rc.NotErrParamNotFound(err) {- fs.Debugf("checkAccess", "optional parameter is missing. using default value: %v", opt.CheckAccess)+ return nil, err}if opt.Force, err = in.GetBool("force"); rc.NotErrParamNotFound(err) {- fs.Debugf("force", "optional parameter is missing. using default value: %v", opt.Force)+ return nil, err}if opt.MaxDeleteRenamesAware, err = in.GetBool("maxDeleteRenamesAware"); rc.NotErrParamNotFound(err) {- fs.Debugf("maxDeleteRenamesAware", "optional parameter is missing. using default value: %v", opt.MaxDeleteRenamesAware)+ return nil, err}if opt.CreateEmptySrcDirs, err = in.GetBool("createEmptySrcDirs"); rc.NotErrParamNotFound(err) {- fs.Debugf("createEmptySrcDirs", "optional parameter is missing. using default value: %v", opt.CreateEmptySrcDirs)+ return nil, err}if opt.RemoveEmptyDirs, err = in.GetBool("removeEmptyDirs"); rc.NotErrParamNotFound(err) {- fs.Debugf("removeEmptyDirs", "optional parameter is missing. using default value: %v", opt.RemoveEmptyDirs)+ return nil, err}if opt.NoCleanup, err = in.GetBool("noCleanup"); rc.NotErrParamNotFound(err) {- fs.Debugf("noCleanup", "optional parameter is missing. using default value: %v", opt.NoCleanup)+ return nil, err}if opt.IgnoreListingChecksum, err = in.GetBool("ignoreListingChecksum"); rc.NotErrParamNotFound(err) {- fs.Debugf("ignoreListingChecksum", "optional parameter is missing. using default value: %v", opt.IgnoreListingChecksum)+ return nil, err}if opt.Resilient, err = in.GetBool("resilient"); rc.NotErrParamNotFound(err) {- fs.Debugf("resilient", "optional parameter is missing. using default value: %v", opt.Resilient)+ return nil, err}if opt.CheckFilename, err = in.GetString("checkFilename"); rc.NotErrParamNotFound(err) {- opt.CheckFilename = DefaultCheckFilename- fs.Debugf("checkFilename", "optional parameter is missing. using default value: %v", opt.CheckFilename)+ return nil, err}if opt.FiltersFile, err = in.GetString("filtersFile"); rc.NotErrParamNotFound(err) {- fs.Debugf("filtersFile", "optional parameter is missing. using default value: %v", opt.FiltersFile)+ return nil, err}if opt.Workdir, err = in.GetString("workdir"); rc.NotErrParamNotFound(err) {- // "" sets correct default later- fs.Debugf("workdir", "optional parameter is missing. using default value: %v", opt.Workdir)+ return nil, err}- if opt.BackupDir1, err = in.GetString("backupDir1"); rc.NotErrParamNotFound(err) {- // we accept an alternate capitalization here for backward compatibility.- if opt.BackupDir1, err = in.GetString("backupdir1"); rc.NotErrParamNotFound(err) {- fs.Debugf("backupDir1", "optional parameter is missing. using default value: %v", opt.BackupDir1)- }+ if opt.BackupDir1, err = in.GetString("backupDir1"); rc.IsErrParamNotFound(err) {+ opt.BackupDir1, err = in.GetString("backupdir1") // the name before v1.74}- if opt.BackupDir2, err = in.GetString("backupDir2"); rc.NotErrParamNotFound(err) {- // we accept an alternate capitalization here for backward compatibility.- if opt.BackupDir2, err = in.GetString("backupdir2"); rc.NotErrParamNotFound(err) {- fs.Debugf("backupDir2", "optional parameter is missing. using default value: %v", opt.BackupDir2)- }+ if rc.NotErrParamNotFound(err) {+ return nil, err+ }+ if opt.BackupDir2, err = in.GetString("backupDir2"); rc.IsErrParamNotFound(err) {+ opt.BackupDir2, err = in.GetString("backupdir2") // the name before v1.74+ }+ if rc.NotErrParamNotFound(err) {+ return nil, err}if err = setEnum(in, "checkSync", "true", opt.CheckSync.Set); err != nil {return nil, err@@ -144,26 +142,25 @@ func rcBisync(ctx context.Context, in rc.Params) (out rc.Params, err error) {return nil, err}if opt.ConflictSuffixFlag, err = in.GetString("conflictSuffix"); rc.NotErrParamNotFound(err) {- fs.Debugf("conflictSuffix", "optional parameter is missing. using default value: %v", opt.ConflictSuffixFlag)+ return nil, err}if opt.Recover, err = in.GetBool("recover"); rc.NotErrParamNotFound(err) {- fs.Debugf("recover", "optional parameter is missing. using default value: %v", opt.Recover)+ return nil, err}if opt.CompareFlag, err = in.GetString("compare"); rc.NotErrParamNotFound(err) {- fs.Debugf("compare", "optional parameter is missing. using default value: %v", opt.CompareFlag)+ return nil, err}if opt.Compare.NoSlowHash, err = in.GetBool("noSlowHash"); rc.NotErrParamNotFound(err) {- fs.Debugf("noSlowHash", "optional parameter is missing. using default value: %v", opt.Compare.NoSlowHash)+ return nil, err}if opt.Compare.SlowHashSyncOnly, err = in.GetBool("slowHashSyncOnly"); rc.NotErrParamNotFound(err) {- fs.Debugf("slowHashSyncOnly", "optional parameter is missing. using default value: %v", opt.Compare.SlowHashSyncOnly)+ return nil, err}if opt.Compare.DownloadHash, err = in.GetBool("downloadHash"); rc.NotErrParamNotFound(err) {- fs.Debugf("downloadHash", "optional parameter is missing. using default value: %v", opt.Compare.DownloadHash)+ return nil, err}if opt.MaxLock, err = in.GetFsDuration("maxLock"); rc.NotErrParamNotFound(err) {- opt.MaxLock = 0- fs.Debugf("maxLock", "optional parameter is missing. using default value: %v", opt.MaxLock)+ return nil, err}fs1, err := rc.GetFsNamed(octx, in, "path1")@@ -200,12 +197,11 @@ func rcBisync(ctx context.Context, in rc.Params) (out rc.Params, err error) {func setEnum(in rc.Params, name string, defaultVal string, set func(s string) error) error {v, err := in.GetString(name)- if rc.NotErrParamNotFound(err) || v == "" {- v = defaultVal- fs.Debugf(name, "optional parameter is missing. using default value: %v", v)- }- if err := set(v); err != nil {+ if rc.NotErrParamNotFound(err) {return err}- return nil+ if v == "" {+ v = defaultVal+ }+ return set(v)}diff --git a/cmd/bisync/rc_test.go b/cmd/bisync/rc_test.goindex 5431f27f3..a5f424d69 100644--- a/cmd/bisync/rc_test.go+++ b/cmd/bisync/rc_test.go@@ -6,6 +6,7 @@ import ("os""path/filepath""testing"+ "time""github.com/rclone/rclone/fs""github.com/rclone/rclone/fs/rc"@@ -122,3 +123,112 @@ func TestRcMaxDeleteFromRcd(t *testing.T) {})}}++func TestRcInvalidParams(t *testing.T) {+ for _, test := range []struct {+ key string+ value any+ }{+ {"force", "yes"},+ {"maxDeleteRenamesAware", "yes"},+ {"filtersFile", []string{"filters.txt"}},+ {"checkSync", 1},+ {"conflictResolve", "bogus"},+ {"maxLock", "soon"},+ } {+ t.Run(test.key, func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 1)+ require.NoError(t, os.WriteFile(filepath.Join(path1, "new.txt"), []byte("new"), 0o644))+ err := run(rc.Params{test.key: test.value})+ assert.Error(t, err)+ assert.NoFileExists(t, filepath.Join(path2, "new.txt"))+ })+ }+}++func TestRcBackupDir(t *testing.T) {+ for _, test := range []struct {+ key string+ changed int // the path whose change overwrites the file on the other path+ }{+ {"backupDir1", 2},+ {"backupdir1", 2},+ {"backupDir2", 1},+ {"backupdir2", 1},+ } {+ t.Run(test.key, func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 2)+ backupDir := filepath.Join(filepath.Dir(path1), "backup")+ changedPath := map[int]string{1: path1, 2: path2}[test.changed]+ require.NoError(t, os.WriteFile(filepath.Join(changedPath, "file0.txt"), []byte("changed"), 0o644))+ require.NoError(t, run(rc.Params{test.key: backupDir}))+ assert.FileExists(t, filepath.Join(backupDir, "file0.txt"))+ })+ }+}++func TestRcEnums(t *testing.T) {+ read := func(t *testing.T, path string) string {+ b, err := os.ReadFile(filepath.Join(path, "file0.txt"))+ require.NoError(t, err)+ return string(b)+ }+ // changeBoth makes file0.txt differ on both paths, with Path2 an hour newer+ changeBoth := func(t *testing.T, path1, path2 string) {+ now := time.Now()+ for path, content := range map[string]string{path1: "path1", path2: "path2 wins"} {+ file := filepath.Join(path, "file0.txt")+ require.NoError(t, os.WriteFile(file, []byte(content), 0o644))+ mtime := now+ if path == path1 {+ mtime = now.Add(-time.Hour)+ }+ require.NoError(t, os.Chtimes(file, mtime, mtime))+ }+ }+ names := func(t *testing.T, path string) (names []string) {+ entries, err := os.ReadDir(path)+ require.NoError(t, err)+ for _, e := range entries {+ names = append(names, e.Name())+ }+ return names+ }+ t.Run("conflictResolve and conflictLoser", func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 2)+ changeBoth(t, path1, path2)+ require.NoError(t, run(rc.Params{"conflictResolve": "path2", "conflictLoser": "delete"}))+ for _, path := range []string{path1, path2} {+ assert.Equal(t, []string{"file0.txt", "file1.txt"}, names(t, path))+ assert.Equal(t, "path2 wins", read(t, path))+ }+ })+ t.Run("conflict defaults", func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 2)+ changeBoth(t, path1, path2)+ require.NoError(t, run(rc.Params{}))+ assert.NotContains(t, names(t, path1), "file0.txt", "with no winner both versions are renamed")+ })+ for _, test := range []struct {+ name string+ in rc.Params+ want string+ }{+ {"resyncMode default", rc.Params{"resync": true}, "path1"},+ {"resyncMode path2", rc.Params{"resync": true, "resyncMode": "path2"}, "path2 wins"},+ } {+ t.Run(test.name, func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 2)+ changeBoth(t, path1, path2)+ require.NoError(t, run(test.in))+ assert.Equal(t, test.want, read(t, path1))+ assert.Equal(t, test.want, read(t, path2))+ })+ }+ t.Run("checkSync only", func(t *testing.T) {+ path1, path2, run := newRcBisync(t, 1)+ require.NoError(t, os.WriteFile(filepath.Join(path1, "new.txt"), []byte("new"), 0o644))+ require.NoError(t, run(rc.Params{"checkSync": "only"}))+ assert.NoFileExists(t, filepath.Join(path2, "new.txt"))+ })+}diff --git a/docs/content/bisync.md b/docs/content/bisync.mdindex 85d0f833b..5d72c63ad 100644--- a/docs/content/bisync.md+++ b/docs/content/bisync.md@@ -1952,6 +1952,10 @@ modtime was less than a second earlier than the one in the listing.- Fixed an issue causing the rc `sync/bisync` call to ignore the global`--max-delete` and use a limit of 0% when `maxDelete` was not set.- `--max-delete` now enforces a maximum of 100.+- Fixed an issue causing the rc `sync/bisync` call to ignore the `backupdir1` and+`backupdir2` parameters (the names used before v1.74).+- Fixed an issue causing the rc `sync/bisync` call to treat a parameter with an+invalid value as if it were missing, instead of returning an error.### `v1.74.2`