diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go index 7e419c4b9..337f744ee 100644 --- a/cmd/bisync/bisync_test.go +++ b/cmd/bisync/bisync_test.go @@ -1163,6 +1163,10 @@ func (b *bisyncTest) newReplacer(mangle bool) *strings.Replacer { b.workDir + slash, "{workdir/}", b.path1, "{path1/}", b.path2, "{path2/}", + "//?/" + strings.TrimSuffix(strings.Replace(b.path1, slash, "/", -1), "/"), "{path1}", // fix windows-specific issue + "//?/" + strings.TrimSuffix(strings.Replace(b.path2, slash, "/", -1), "/"), "{path2}", + strings.TrimSuffix(b.path1, slash), "{path1}", // ensure it's still recognized without trailing slash + strings.TrimSuffix(b.path2, slash), "{path2}", b.sessionName, "{session}", } if fixSlash { diff --git a/cmd/bisync/cmd.go b/cmd/bisync/cmd.go index 17c87f1cc..d08583c7d 100644 --- a/cmd/bisync/cmd.go +++ b/cmd/bisync/cmd.go @@ -210,9 +210,13 @@ func (opt *Options) applyFilters(ctx context.Context) (context.Context, error) { } if opt.Resync { + if opt.DryRun { + fs.Infof(nil, "Skipped storing filters file hash to %s as --dry-run is set", hashFile) + } else { fs.Infof(nil, "Storing filters file hash to %s", hashFile) if err := os.WriteFile(hashFile, []byte(gotHash), bilib.PermSecure); err != nil { return ctx, err + } } } diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry new file mode 100644 index 000000000..844684626 --- /dev/null +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry @@ -0,0 +1,5 @@ +# bisync listing v1 from test +- 109 md5:294d25b294ff26a5243dba914ac3fbf7 - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file1.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file2.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "subdir/file20.txt" diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry-new b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry-new new file mode 100644 index 000000000..844684626 --- /dev/null +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path1.lst-dry-new @@ -0,0 +1,5 @@ +# bisync listing v1 from test +- 109 md5:294d25b294ff26a5243dba914ac3fbf7 - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file1.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file2.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "subdir/file20.txt" diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry new file mode 100644 index 000000000..844684626 --- /dev/null +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry @@ -0,0 +1,5 @@ +# bisync listing v1 from test +- 109 md5:294d25b294ff26a5243dba914ac3fbf7 - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file1.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file2.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "subdir/file20.txt" diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry-new b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry-new new file mode 100644 index 000000000..844684626 --- /dev/null +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/_testdir_path1.._testdir_path2.path2.lst-dry-new @@ -0,0 +1,5 @@ +# bisync listing v1 from test +- 109 md5:294d25b294ff26a5243dba914ac3fbf7 - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file1.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "file2.txt" +- 0 md5:d41d8cd98f00b204e9800998ecf8427e - 2000-01-01T00:00:00.000000000+0000 "subdir/file20.txt" diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log b/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log index 606e06ef7..ab50cf9cf 100644 --- a/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log @@ -58,3 +58,21 @@ INFO : Using filters file {workdir/}filtersfile.txt ERROR : Bisync critical error: filters file has changed (must run --resync): {workdir/}filtersfile.txt ERROR : Bisync aborted. Must run --resync to recover. Bisync error: bisync aborted + +(18) : test 8. run with filters-file and resync and dry-run. should do the dry-run but still cause next non-resync run to abort. +(19) : bisync filters-file={workdir/}filtersfile.txt resync dry-run +INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" +INFO : Using filters file {workdir/}filtersfile.txt +INFO : Skipped storing filters file hash to {workdir/}filtersfile.txt.md5 as --dry-run is set +INFO : Copying unique Path2 files to Path1 +INFO : Resynching Path1 to Path2 +INFO : Resync updating listings +INFO : Bisync successful + +(20) : test 9. run with filters-file alone. should abort. +(21) : bisync filters-file={workdir/}filtersfile.txt +INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" +INFO : Using filters file {workdir/}filtersfile.txt +ERROR : Bisync critical error: filters file has changed (must run --resync): {workdir/}filtersfile.txt +ERROR : Bisync aborted. Must run --resync to recover. +Bisync error: bisync aborted diff --git a/cmd/bisync/testdata/test_filtersfile_checks/scenario.txt b/cmd/bisync/testdata/test_filtersfile_checks/scenario.txt index 0cb206cef..fa8054799 100644 --- a/cmd/bisync/testdata/test_filtersfile_checks/scenario.txt +++ b/cmd/bisync/testdata/test_filtersfile_checks/scenario.txt @@ -34,3 +34,9 @@ copy-as {datadir/}filtersfile2.txt {workdir/} filtersfile.txt test 7. run with filters-file alone. should abort. bisync filters-file={workdir/}filtersfile.txt + +test 8. run with filters-file and resync and dry-run. should do the dry-run but still cause next non-resync run to abort. +bisync filters-file={workdir/}filtersfile.txt resync dry-run + +test 9. run with filters-file alone. should abort. +bisync filters-file={workdir/}filtersfile.txt \ No newline at end of file diff --git a/docs/content/bisync.md b/docs/content/bisync.md index f8d0c440f..17778868f 100644 --- a/docs/content/bisync.md +++ b/docs/content/bisync.md @@ -1102,3 +1102,9 @@ See the _Dual Shadow Method_ section in the Also note a number of academic publications by [Benjamin Pierce](http://www.cis.upenn.edu/%7Ebcpierce/papers/index.shtml#File%20Synchronization) about _Unison_ and synchronization in general. + +## Changelog + +### `v1.64` +* Fixed an [issue](https://forum.rclone.org/t/bisync-bugs-and-feature-requests/37636#:~:text=1.%20Dry%20runs%20are%20not%20completely%20dry) +causing dry runs to inadvertently commit filter changes