Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

bisync: fix --conflict-loser pathname with --conflict-resolve newer

nielash35752d007950
diff --git a/cmd/bisync/resolve.go b/cmd/bisync/resolve.go
index 0263201e2..fd2423c13 100644
--- a/cmd/bisync/resolve.go
+++ b/cmd/bisync/resolve.go
@@ -165,6 +165,16 @@ func (b *bisyncRun) resolve(ctxMove context.Context, path1, path2, file, alias s
},
}
+ if b.opt.ConflictLoser == ConflictLoserPathname {
+ switch winningPath {
+ case 1: // keep path1, rename path2
+ r.path1.newName = r.path1.oldName
+ case 2: // keep path2, rename path1
+ r.path2.newName = r.path2.oldName
+ }
+ // case 0 keeps default
+ }
+
// handle auto-numbering
// note that we still queue copies for both files, whether or not we renamed
// we also set these for ConflictLoserDelete in case there is no winner.
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.copy2to1.que b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.copy2to1.que
index 9ed593ba3..886874627 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.copy2to1.que
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.copy2to1.que
@@ -1 +1 @@
-"file2.txt"
+"file1.txt.path2"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst
index 57872a027..d7d83c7e5 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst
@@ -1,6 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
-- 33 - - 2006-03-04T00:00:00.000000000+0000 "file1.txt"
+- 33 - - 2004-07-25T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
@@ -8,3 +8,5 @@
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.cloud1"
- 33 - - 2001-08-26T00:00:00.000000000+0000 "file1.txt.dinosaur1"
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.local1"
+- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt.path2"
+- 33 - - 2006-03-04T00:00:00.000000000+0000 "file2.txt"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-new b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-new
index 454d9344c..07b7abe00 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-new
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-new
@@ -1,6 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
-- 33 - - 2006-03-04T00:00:00.000000000+0000 "file1.txt"
+- 33 - - 2004-07-25T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
@@ -8,4 +8,4 @@
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.cloud1"
- 33 - - 2001-08-26T00:00:00.000000000+0000 "file1.txt.dinosaur1"
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.local1"
-- 33 - - 2005-01-02T00:00:00.000000000+0000 "file2.txt"
+- 33 - - 2006-03-04T00:00:00.000000000+0000 "file2.txt"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-old b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-old
index 2779be7ab..57872a027 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-old
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path1.lst-old
@@ -1,5 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
+- 33 - - 2006-03-04T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
@@ -7,4 +8,3 @@
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.cloud1"
- 33 - - 2001-08-26T00:00:00.000000000+0000 "file1.txt.dinosaur1"
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.local1"
-- 0 - - 2000-01-01T00:00:00.000000000+0000 "file2.txt"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst
index 57872a027..d7d83c7e5 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst
@@ -1,6 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
-- 33 - - 2006-03-04T00:00:00.000000000+0000 "file1.txt"
+- 33 - - 2004-07-25T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
@@ -8,3 +8,5 @@
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.cloud1"
- 33 - - 2001-08-26T00:00:00.000000000+0000 "file1.txt.dinosaur1"
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.local1"
+- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt.path2"
+- 33 - - 2006-03-04T00:00:00.000000000+0000 "file2.txt"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-new b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-new
index 8b02b6d6a..6c7698203 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-new
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-new
@@ -1,6 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
-- 33 - - 2005-01-02T00:00:00.000000000+0000 "file1.txt"
+- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
diff --git a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-old b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-old
index 2779be7ab..57872a027 100644
--- a/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-old
+++ b/cmd/bisync/testdata/test_resolve/golden/_testdir_path1.._testdir_path2.path2.lst-old
@@ -1,5 +1,6 @@
# bisync listing v1 from test
- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST"
+- 33 - - 2006-03-04T00:00:00.000000000+0000 "file1.txt"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path1"
- 33 - - 2004-07-23T00:00:00.000000000+0000 "file1.txt..path2"
- 33 - - 2002-08-26T00:00:00.000000000+0000 "file1.txt.apple1"
@@ -7,4 +8,3 @@
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.cloud1"
- 33 - - 2001-08-26T00:00:00.000000000+0000 "file1.txt.dinosaur1"
- 33 - - 2003-07-23T00:00:00.000000000+0000 "file1.txt.local1"
-- 0 - - 2000-01-01T00:00:00.000000000+0000 "file2.txt"
diff --git a/cmd/bisync/testdata/test_resolve/golden/test.log b/cmd/bisync/testdata/test_resolve/golden/test.log
index 27281e261..fb4d03c0c 100644
--- a/cmd/bisync/testdata/test_resolve/golden/test.log
+++ b/cmd/bisync/testdata/test_resolve/golden/test.log
@@ -305,3 +305,56 @@ INFO : - Path1 Do queued copies to - P
INFO : Updating listings
INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}"
INFO : Bisync successful
+
+(48) : test --conflict-resolve newer --conflict-loser pathname --conflict-suffix path
+(49) : touch-glob 2004-07-23 {datadir/} file1R.txt
+(50) : copy-as {datadir/}file1R.txt {path2/} file1.txt
+(51) : touch-glob 2004-07-25 {datadir/} file1L.txt
+(52) : copy-as {datadir/}file1L.txt {path1/} file1.txt
+
+(53) : test bisync run with --conflict-resolve=newer --conflict-loser=pathname --conflict-suffix=path
+
+(54) : bisync conflict-resolve=newer conflict-loser=pathname conflict-suffix=path
+INFO : Setting --ignore-listing-checksum as neither --checksum nor --compare checksum are set.
+INFO : Bisyncing with Comparison Settings:
+{
+"Modtime": true,
+"Size": true,
+"Checksum": false,
+"NoSlowHash": false,
+"SlowHashSyncOnly": false,
+"DownloadHash": false
+}
+INFO : Synching Path1 "{path1/}" with Path2 "{path2/}"
+INFO : Building Path1 and Path2 listings
+INFO : Path1 checking for diffs
+INFO : - Path1 File changed: time (older) - file1.txt
+INFO : - Path1 File is new - file2.txt
+INFO : Path1: 2 changes:  1 new,  1 modified,  0 deleted
+INFO : (Modified:  0 newer,  1 older)
+INFO : Path2 checking for diffs
+INFO : - Path2 File changed: time (older) - file1.txt
+INFO : - Path2 File is new - file2.txt
+INFO : Path2: 2 changes:  1 new,  1 modified,  0 deleted
+INFO : (Modified:  0 newer,  1 older)
+INFO : Applying changes
+INFO : Checking potential conflicts...
+ERROR : file1.txt: {hashtype} differ
+NOTICE: {path2String}: 1 differences found
+NOTICE: {path2String}: 1 errors while checking
+NOTICE: {path2String}: 1 matching files
+INFO : Finished checking the potential conflicts. 1 differences found
+NOTICE: - WARNING New or changed in both paths - file1.txt
+INFO : file1.txt: Path1 is newer. Path1: 2004-07-25 00:00:00 +0000 UTC, Path2: 2004-07-23 00:00:00 +0000 UTC, Difference: 48h0m0s
+INFO : file1.txt: The winner is: Path1
+NOTICE: - Path1 Not renaming Path1 copy, as it was determined the winner - {path1/}file1.txt
+NOTICE: - Path1 Queue copy to Path2 - {path2/}file1.txt
+NOTICE: - Path2 Renaming Path2 copy - {path2/}file1.txt.path2
+NOTICE: - Path2 Queue copy to Path1 - {path1/}file1.txt.path2
+NOTICE: - WARNING New or changed in both paths - file2.txt
+INFO : Files are equal! Skipping: file2.txt
+INFO : - Path2 Do queued copies to - Path1
+INFO : - Path1 Do queued copies to - Path2
+INFO : Updating listings
+INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}"
+INFO : Bisync successful
diff --git a/cmd/bisync/testdata/test_resolve/scenario.txt b/cmd/bisync/testdata/test_resolve/scenario.txt
index 1e72757f7..f8197806e 100644
--- a/cmd/bisync/testdata/test_resolve/scenario.txt
+++ b/cmd/bisync/testdata/test_resolve/scenario.txt
@@ -64,4 +64,14 @@ copy-as {datadir/}file1L.txt {path1/} file1.txt
copy-as {datadir/}file1L.txt {path2/} file2.txt
test bisync run with --conflict-resolve=newer --conflict-loser=delete
-bisync conflict-resolve=newer conflict-loser=delete
\ No newline at end of file
+bisync conflict-resolve=newer conflict-loser=delete
+
+test --conflict-resolve newer --conflict-loser pathname --conflict-suffix path
+touch-glob 2004-07-23 {datadir/} file1R.txt
+copy-as {datadir/}file1R.txt {path2/} file1.txt
+touch-glob 2004-07-25 {datadir/} file1L.txt
+copy-as {datadir/}file1L.txt {path1/} file1.txt
+
+test bisync run with --conflict-resolve=newer --conflict-loser=pathname --conflict-suffix=path
+# result should be -- "file1.txt", "file1.txt.path2"
+bisync conflict-resolve=newer conflict-loser=pathname conflict-suffix=path
\ No newline at end of file
diff --git a/docs/content/bisync.md b/docs/content/bisync.md
index 98f7a9100..c2e3a0012 100644
--- a/docs/content/bisync.md
+++ b/docs/content/bisync.md
@@ -1899,6 +1899,11 @@ about *Unison* and synchronization in general.
## Changelog
+### `v1.74.2`
+
+- Fixed an issue causing `--conflict-loser pathname` to produce unexpected
+behavior if using a non-default `--conflict-resolve` value.
+
### `v1.74`
- Added several missing `rc` parameters.