From 810644e8735330db1cbd70745802284e8624b423 Mon Sep 17 00:00:00 2001 From: nielash Date: Fri, 22 Dec 2023 14:09:35 -0500 Subject: [PATCH] bisync: add --resync-mode for customizing --resync - fixes #5681 Before this change, the path1 version of a file always prevailed during --resync, and many users requested options to automatically select the winner based on characteristics such as newer, older, larger, and smaller. This change adds support for such options. Note that ideally this feature would have been implemented by allowing the existing `--resync` flag to optionally accept string values such as `--resync newer`. However, this would have been a breaking change, as the existing flag is a `bool` and it does not seem to be possible to have a `string` flag that accepts both `--resync newer` and `--resync` (with no argument.) (`NoOptDefVal` does not work for this, as it would force an `=` like `--resync=newer`.) So instead, the best compromise to avoid a breaking change was to add a new `--resync-mode CHOICE` flag that implies `--resync`, while maintaining the existing behavior of `--resync` (which implies `--resync-mode path1`. i.e. both flags are now valid, and either can be used without the other. --resync-mode CHOICE In the event that a file differs on both sides during a `--resync`, `--resync-mode` controls which version will overwrite the other. The supported options are similar to `--conflict-resolve`. For all of the following options, the version that is kept is referred to as the "winner", and the version that is overwritten (deleted) is referred to as the "loser". The options are named after the "winner": - `path1` - (the default) - the version from Path1 is unconditionally considered the winner (regardless of `modtime` and `size`, if any). This can be useful if one side is more trusted or up-to-date than the other, at the time of the `--resync`. - `path2` - same as `path1`, except the path2 version is considered the winner. - `newer` - the newer file (by `modtime`) is considered the winner, regardless of which side it came from. This may result in having a mix of some winners from Path1, and some winners from Path2. (The implementation is analagous to running `rclone copy --update` in both directions.) - `older` - same as `newer`, except the older file is considered the winner, and the newer file is considered the loser. - `larger` - the larger file (by `size`) is considered the winner (regardless of `modtime`, if any). This can be a useful option for remotes without `modtime` support, or with the kinds of files (such as logs) that tend to grow but not shrink, over time. - `smaller` - the smaller file (by `size`) is considered the winner (regardless of `modtime`, if any). For all of the above options, note the following: - If either of the underlying remotes lacks support for the chosen method, it will be ignored and will fall back to the default of `path1`. (For example, if `--resync-mode newer` is set, but one of the paths uses a remote that doesn't support `modtime`.) - If a winner can't be determined because the chosen method's attribute is missing or equal, it will be ignored, and bisync will instead try to determine whether the files differ by looking at the other `--compare` methods in effect. (For example, if `--resync-mode newer` is set, but the Path1 and Path2 modtimes are identical, bisync will compare the sizes.) If bisync concludes that they differ, preference is given to whichever is the "source" at that moment. (In practice, this gives a slight advantage to Path2, as the 2to1 copy comes before the 1to2 copy.) If the files _do not_ differ, nothing is copied (as both sides are already correct). - These options apply only to files that exist on both sides (with the same name and relative path). Files that exist *only* on one side and not the other are *always* copied to the other, during `--resync` (this is one of the main differences between resync and non-resync runs.). - `--conflict-resolve`, `--conflict-loser`, and `--conflict-suffix` do not apply during `--resync`, and unlike these flags, nothing is renamed during `--resync`. When a file differs on both sides during `--resync`, one version always overwrites the other (much like in `rclone copy`.) (Consider using `--backup-dir` to retain a backup of the losing version.) - Unlike for `--conflict-resolve`, `--resync-mode none` is not a valid option (or rather, it will be interpreted as "no resync", unless `--resync` has also been specified, in which case it will be ignored.) - Winners and losers are decided at the individual file-level only (there is not currently an option to pick an entire winning directory atomically, although the `path1` and `path2` options typically produce a similar result.) - To maintain backward-compatibility, the `--resync` flag implies `--resync-mode path1` unless a different `--resync-mode` is explicitly specified. Similarly, all `--resync-mode` options (except `none`) imply `--resync`, so it is not necessary to use both the `--resync` and `--resync-mode` flags simultaneously -- either one is sufficient without the other. --- cmd/bisync/bisync_test.go | 3 + cmd/bisync/checkfn.go | 38 +++- cmd/bisync/cmd.go | 8 +- cmd/bisync/operations.go | 4 + cmd/bisync/queue.go | 5 + cmd/bisync/resolve.go | 14 +- cmd/bisync/resync.go | 104 +++++++++- .../testdata/test_all_changed/golden/test.log | 7 +- .../testdata/test_backupdir/golden/test.log | 7 +- .../testdata/test_basic/golden/test.log | 7 +- .../testdata/test_changes/golden/test.log | 7 +- .../test_check_access/golden/test.log | 21 +- .../test_check_access_filters/golden/test.log | 14 +- .../test_check_filename/golden/test.log | 14 +- .../testdata/test_check_sync/golden/test.log | 14 +- .../testdata/test_compare_all/golden/test.log | 7 +- .../test_createemptysrcdirs/golden/test.log | 14 +- .../testdata/test_dry_run/golden/test.log | 13 +- .../testdata/test_equal/golden/test.log | 7 +- .../test_extended_char_paths/golden/test.log | 28 +-- .../test_extended_filenames/golden/test.log | 7 +- .../testdata/test_filters/golden/test.log | 7 +- .../test_filtersfile_checks/golden/test.log | 20 +- .../golden/test.log | 14 +- .../test_max_delete_path1/golden/test.log | 7 +- .../golden/test.log | 7 +- .../test_normalization/golden/test.log | 21 +- .../testdata/test_rclone_args/golden/test.log | 21 +- .../testdata/test_resolve/golden/test.log | 9 +- .../testdata/test_resync/golden/test.log | 21 +- .../_testdir_path1.._testdir_path2.path1.lst | 4 + ...estdir_path1.._testdir_path2.path1.lst-new | 1 + ...estdir_path1.._testdir_path2.path1.lst-old | 4 + .../_testdir_path1.._testdir_path2.path2.lst | 4 + ...estdir_path1.._testdir_path2.path2.lst-new | 1 + ...estdir_path1.._testdir_path2.path2.lst-old | 4 + .../test_resync_modes/golden/test.log | 192 ++++++++++++++++++ .../test_resync_modes/initial/RCLONE_TEST | 1 + .../test_resync_modes/initial/file1.txt | 0 .../test_resync_modes/initial/file2.txt | 0 .../test_resync_modes/modfiles/file1L.txt | 1 + .../test_resync_modes/modfiles/file1R.txt | 1 + .../test_resync_modes/modfiles/file2.txt | 1 + .../testdata/test_resync_modes/scenario.txt | 70 +++++++ .../testdata/test_rmdirs/golden/test.log | 7 +- .../testdata/test_volatile/golden/test.log | 7 +- docs/content/bisync.md | 94 ++++++++- 47 files changed, 706 insertions(+), 156 deletions(-) create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-new create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-old create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-new create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-old create mode 100644 cmd/bisync/testdata/test_resync_modes/golden/test.log create mode 100644 cmd/bisync/testdata/test_resync_modes/initial/RCLONE_TEST create mode 100644 cmd/bisync/testdata/test_resync_modes/initial/file1.txt create mode 100644 cmd/bisync/testdata/test_resync_modes/initial/file2.txt create mode 100644 cmd/bisync/testdata/test_resync_modes/modfiles/file1L.txt create mode 100644 cmd/bisync/testdata/test_resync_modes/modfiles/file1R.txt create mode 100644 cmd/bisync/testdata/test_resync_modes/modfiles/file2.txt create mode 100644 cmd/bisync/testdata/test_resync_modes/scenario.txt diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go index a3e08fefa..288371b7f 100644 --- a/cmd/bisync/bisync_test.go +++ b/cmd/bisync/bisync_test.go @@ -205,6 +205,7 @@ func TestBisync(t *testing.T) { ci.RefreshTimes = true } bisync.Colors = true + time.Local, _ = time.LoadLocation("America/New_York") baseDir, err := os.Getwd() require.NoError(t, err, "get current directory") @@ -865,6 +866,8 @@ func (b *bisyncTest) runBisync(ctx context.Context, args []string) (err error) { _ = opt.ConflictLoser.Set(val) case "conflict-suffix": opt.ConflictSuffixFlag = val + case "resync-mode": + _ = opt.ResyncMode.Set(val) default: return fmt.Errorf("invalid bisync option %q", arg) } diff --git a/cmd/bisync/checkfn.go b/cmd/bisync/checkfn.go index c5d5c12b5..8cc6e13c4 100644 --- a/cmd/bisync/checkfn.go +++ b/cmd/bisync/checkfn.go @@ -208,7 +208,14 @@ func (b *bisyncRun) EqualFn(ctx context.Context) context.Context { fs.Debugf(src, "equal skipped") } ctxNoLogger := operations.WithLogger(ctx, noop) - if operations.Equal(ctxNoLogger, src, dst) { + + timeSizeEqualFn := func() (equal bool, skipHash bool) { return operations.Equal(ctxNoLogger, src, dst), false } // normally use Equal() + if b.opt.ResyncMode == PreferOlder || b.opt.ResyncMode == PreferLarger || b.opt.ResyncMode == PreferSmaller { + timeSizeEqualFn = func() (equal bool, skipHash bool) { return b.resyncTimeSizeEqual(ctxNoLogger, src, dst) } // but override for --resync-mode older, larger, smaller + } + skipHash := false // (note that we might skip it anyway based on compare/ht settings) + equal, skipHash = timeSizeEqualFn() + if equal && !skipHash { whichHashType := func(f fs.Info) hash.Type { ht := getHashType(f.Name()) if ht == hash.None && b.opt.Compare.SlowHashSyncOnly && !b.opt.Resync { @@ -233,3 +240,32 @@ func (b *bisyncRun) EqualFn(ctx context.Context) context.Context { } return operations.WithEqualFn(ctx, equalFn) } + +func (b *bisyncRun) resyncTimeSizeEqual(ctxNoLogger context.Context, src fs.ObjectInfo, dst fs.Object) (equal bool, skipHash bool) { + switch b.opt.ResyncMode { + case PreferLarger, PreferSmaller: + // note that arg order is path1, path2, regardless of src/dst + path1, path2 := b.resyncWhichIsWhich(src, dst) + if sizeDiffers(path1.Size(), path2.Size()) { + winningPath := b.resolveLargerSmaller(path1.Size(), path2.Size(), path1.Remote(), path2.Remote(), b.opt.ResyncMode) + // don't need to check/update modtime here, as sizes definitely differ and something will be transferred + return b.resyncWinningPathToEqual(winningPath), b.resyncWinningPathToEqual(winningPath) // skip hash check if true + } + // sizes equal or don't know, so continue to checking time/hash, if applicable + return operations.Equal(ctxNoLogger, src, dst), false // note we're back to src/dst, not path1/path2 + case PreferOlder: + // note that arg order is path1, path2, regardless of src/dst + path1, path2 := b.resyncWhichIsWhich(src, dst) + if timeDiffers(ctxNoLogger, path1.ModTime(ctxNoLogger), path2.ModTime(ctxNoLogger), path1.Fs(), path2.Fs()) { + winningPath := b.resolveNewerOlder(path1.ModTime(ctxNoLogger), path2.ModTime(ctxNoLogger), path1.Remote(), path2.Remote(), b.opt.ResyncMode) + // if src is winner, proceed with equal to check size/hash and possibly just update dest modtime instead of transferring + if !b.resyncWinningPathToEqual(winningPath) { + return operations.Equal(ctxNoLogger, src, dst), false // note we're back to src/dst, not path1/path2 + } + // if dst is winner (and definitely unequal), do not proceed further as we want dst to overwrite src regardless of size difference, and we do not want dest modtime updated + return true, true + } + // times equal or don't know, so continue to checking size/hash, if applicable + } + return operations.Equal(ctxNoLogger, src, dst), false // note we're back to src/dst, not path1/path2 +} diff --git a/cmd/bisync/cmd.go b/cmd/bisync/cmd.go index 17442c9ea..b57bbf1ee 100644 --- a/cmd/bisync/cmd.go +++ b/cmd/bisync/cmd.go @@ -30,7 +30,8 @@ type TestFunc func() // Options keep bisync options type Options struct { - Resync bool + Resync bool // whether or not this is a resync + ResyncMode Prefer // which mode to use for resync CheckAccess bool CheckFilename string CheckSync CheckSyncMode @@ -123,7 +124,8 @@ func init() { cmdFlags := commandDefinition.Flags() // when adding new flags, remember to also update the rc params: // cmd/bisync/rc.go cmd/bisync/help.go (not docs/content/rc.md) - flags.BoolVarP(cmdFlags, &Opt.Resync, "resync", "1", Opt.Resync, "Performs the resync run. Path1 files may overwrite Path2 versions. Consider using --verbose or --dry-run first.", "") + flags.BoolVarP(cmdFlags, &Opt.Resync, "resync", "1", Opt.Resync, "Performs the resync run. Equivalent to --resync-mode path1. Consider using --verbose or --dry-run first.", "") + flags.FVarP(cmdFlags, &Opt.ResyncMode, "resync-mode", "", "During resync, prefer the version that is: path1, path2, newer, older, larger, smaller (default: path1 if --resync, otherwise none for no resync.)", "") flags.BoolVarP(cmdFlags, &Opt.CheckAccess, "check-access", "", Opt.CheckAccess, makeHelp("Ensure expected {CHECKFILE} files are found on both Path1 and Path2 filesystems, else abort."), "") flags.StringVarP(cmdFlags, &Opt.CheckFilename, "check-filename", "", Opt.CheckFilename, makeHelp("Filename for --check-access (default: {CHECKFILE})"), "") flags.BoolVarP(cmdFlags, &Opt.Force, "force", "", Opt.Force, "Bypass --max-delete safety check and run the sync. Consider using with --verbose", "") @@ -149,6 +151,8 @@ func init() { flags.FVarP(cmdFlags, &Opt.ConflictResolve, "conflict-resolve", "", "Automatically resolve conflicts by preferring the version that is: "+ConflictResolveList+" (default: none)", "") flags.FVarP(cmdFlags, &Opt.ConflictLoser, "conflict-loser", "", "Action to take on the loser of a sync conflict (when there is a winner) or on both files (when there is no winner): "+ConflictLoserList+" (default: num)", "") flags.StringVarP(cmdFlags, &Opt.ConflictSuffixFlag, "conflict-suffix", "", Opt.ConflictSuffixFlag, "Suffix to use when renaming a --conflict-loser. Can be either one string or two comma-separated strings to assign different suffixes to Path1/Path2. (default: 'conflict')", "") + _ = cmdFlags.MarkHidden("debugname") + _ = cmdFlags.MarkHidden("localtime") } // bisync command definition diff --git a/cmd/bisync/operations.go b/cmd/bisync/operations.go index 79ed630f3..432ceaee4 100644 --- a/cmd/bisync/operations.go +++ b/cmd/bisync/operations.go @@ -50,6 +50,7 @@ type bisyncRun struct { DebugName string lockFile string renames renames + resyncIs1to2 bool } type queues struct { @@ -89,6 +90,9 @@ func Bisync(ctx context.Context, fs1, fs2 fs.Fs, optArg *Options) (err error) { if err != nil { return err } + + b.setResyncDefaults() + err = b.setResolveDefaults(ctx) if err != nil { return err diff --git a/cmd/bisync/queue.go b/cmd/bisync/queue.go index 120b9e9bd..8b5cd0801 100644 --- a/cmd/bisync/queue.go +++ b/cmd/bisync/queue.go @@ -202,6 +202,11 @@ func (b *bisyncRun) preCopy(ctx context.Context) context.Context { // otherwise impossible in Sync, so override Equal ctx = b.EqualFn(ctx) } + if b.opt.ResyncMode == PreferOlder || b.opt.ResyncMode == PreferLarger || b.opt.ResyncMode == PreferSmaller { + overridingEqual = true + fs.Debugf(nil, "overriding equal") + ctx = b.EqualFn(ctx) + } ctxCopyLogger := operations.WithSyncLogger(ctx, logger) if b.opt.Compare.Checksum && (b.opt.Compare.NoSlowHash || b.opt.Compare.SlowHashSyncOnly) && b.opt.Compare.SlowHashDetected { // set here in case !b.opt.Compare.Modtime diff --git a/cmd/bisync/resolve.go b/cmd/bisync/resolve.go index 4daa9527b..e9c57a7d0 100644 --- a/cmd/bisync/resolve.go +++ b/cmd/bisync/resolve.go @@ -44,7 +44,7 @@ func (preferChoices) Choices() []string { } func (preferChoices) Type() string { - return "Prefer" + return "string" } // ConflictResolveList is a list of --conflict-resolve flag choices used in the help @@ -373,21 +373,22 @@ func (b *bisyncRun) conflictWinner(ds1, ds2 *deltaSet, remote1, remote2 string) case PreferPath2: return 2 case PreferNewer, PreferOlder: - return b.resolveNewerOlder(ds1, ds2, remote1, remote2, b.opt.ConflictResolve) + t1, t2 := ds1.time[remote1], ds2.time[remote2] + return b.resolveNewerOlder(t1, t2, remote1, remote2, b.opt.ConflictResolve) case PreferLarger, PreferSmaller: - return b.resolveLargerSmaller(ds1, ds2, remote1, remote2, b.opt.ConflictResolve) + s1, s2 := ds1.size[remote1], ds2.size[remote2] + return b.resolveLargerSmaller(s1, s2, remote1, remote2, b.opt.ConflictResolve) default: return 0 } } // returns the winning path number, or 0 if winner can't be determined -func (b *bisyncRun) resolveNewerOlder(ds1, ds2 *deltaSet, remote1, remote2 string, prefer Prefer) int { +func (b *bisyncRun) resolveNewerOlder(t1, t2 time.Time, remote1, remote2 string, prefer Prefer) int { if fs.GetModifyWindow(b.octx, b.fs1, b.fs2) == fs.ModTimeNotSupported { fs.Infof(remote1, "Winner cannot be determined as at least one path lacks modtime support.") return 0 } - t1, t2 := ds1.time[remote1], ds2.time[remote2] if t1.IsZero() || t2.IsZero() { fs.Infof(remote1, "Winner cannot be determined as at least one modtime is missing. Path1: %v, Path2: %v", t1, t2) return 0 @@ -418,8 +419,7 @@ func (b *bisyncRun) resolveNewerOlder(ds1, ds2 *deltaSet, remote1, remote2 strin } // returns the winning path number, or 0 if winner can't be determined -func (b *bisyncRun) resolveLargerSmaller(ds1, ds2 *deltaSet, remote1, remote2 string, prefer Prefer) int { - s1, s2 := ds1.size[remote1], ds2.size[remote2] +func (b *bisyncRun) resolveLargerSmaller(s1, s2 int64, remote1, remote2 string, prefer Prefer) int { if s1 < 0 || s2 < 0 { fs.Infof(remote1, "Winner cannot be determined as at least one size is unknown. Path1: %v, Path2: %v", s1, s2) return 0 diff --git a/cmd/bisync/resync.go b/cmd/bisync/resync.go index 7d2bd9760..b3fc7ed8d 100644 --- a/cmd/bisync/resync.go +++ b/cmd/bisync/resync.go @@ -8,13 +8,41 @@ import ( "github.com/rclone/rclone/cmd/bisync/bilib" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/filter" + "github.com/rclone/rclone/lib/terminal" ) +// for backward compatibility, --resync is now equivalent to --resync-mode path1 +// and either flag is sufficient without the other. +func (b *bisyncRun) setResyncDefaults() { + if b.opt.Resync && b.opt.ResyncMode == PreferNone { + fs.Debugf(nil, Color(terminal.Dim, "defaulting to --resync-mode path1 as --resync is set")) + b.opt.ResyncMode = PreferPath1 + } + if b.opt.ResyncMode != PreferNone { + b.opt.Resync = true + Opt.Resync = true // shouldn't be using this one, but set to be safe + } + + // checks and warnings + if (b.opt.ResyncMode == PreferNewer || b.opt.ResyncMode == PreferOlder) && (b.fs1.Precision() == fs.ModTimeNotSupported || b.fs2.Precision() == fs.ModTimeNotSupported) { + fs.Logf(nil, Color(terminal.YellowFg, "WARNING: ignoring --resync-mode %s as at least one remote does not support modtimes."), b.opt.ResyncMode.String()) + b.opt.ResyncMode = PreferPath1 + } else if (b.opt.ResyncMode == PreferNewer || b.opt.ResyncMode == PreferOlder) && !b.opt.Compare.Modtime { + fs.Logf(nil, Color(terminal.YellowFg, "WARNING: ignoring --resync-mode %s as --compare does not include modtime."), b.opt.ResyncMode.String()) + b.opt.ResyncMode = PreferPath1 + } + if (b.opt.ResyncMode == PreferLarger || b.opt.ResyncMode == PreferSmaller) && !b.opt.Compare.Size { + fs.Logf(nil, Color(terminal.YellowFg, "WARNING: ignoring --resync-mode %s as --compare does not include size."), b.opt.ResyncMode.String()) + b.opt.ResyncMode = PreferPath1 + } +} + // resync implements the --resync mode. -// It will generate path1 and path2 listings -// and copy any unique path2 files to path1. +// It will generate path1 and path2 listings, +// copy any unique files to the opposite path, +// and resolve any differing files according to the --resync-mode. func (b *bisyncRun) resync(octx, fctx context.Context) error { - fs.Infof(nil, "Copying unique Path2 files to Path1") + fs.Infof(nil, "Copying Path2 files to Path1") // Save blank filelists (will be filled from sync results) var ls1 = newFileList() @@ -74,15 +102,15 @@ func (b *bisyncRun) resync(octx, fctx context.Context) error { var results1to2 []Results queues := queues{} - b.indent("Path2", "Path1", "Resync is copying UNIQUE files to") + b.indent("Path2", "Path1", "Resync is copying files to") ctxRun := b.opt.setDryRun(fctx) // fctx has our extra filters added! ctxSync, filterSync := filter.AddConfig(ctxRun) if filterSync.Opt.MinSize == -1 { fs.Debugf(nil, "filterSync.Opt.MinSize: %v", filterSync.Opt.MinSize) } - ci := fs.GetConfig(ctxSync) - ci.IgnoreExisting = true + b.resyncIs1to2 = false + ctxSync = b.setResyncConfig(ctxSync) ctxSync = b.setBackupDir(ctxSync, 1) // 2 to 1 if results2to1, err = b.resyncDir(ctxSync, b.fs2, b.fs1); err != nil { @@ -90,8 +118,9 @@ func (b *bisyncRun) resync(octx, fctx context.Context) error { return err } - b.indent("Path1", "Path2", "Resync is copying UNIQUE OR DIFFERING files to") - ci.IgnoreExisting = false + b.indent("Path1", "Path2", "Resync is copying files to") + b.resyncIs1to2 = true + ctxSync = b.setResyncConfig(ctxSync) ctxSync = b.setBackupDir(ctxSync, 2) // 1 to 2 if results1to2, err = b.resyncDir(ctxSync, b.fs1, b.fs2); err != nil { @@ -130,9 +159,68 @@ func (b *bisyncRun) resync(octx, fctx context.Context) error { return err } + if b.opt.CheckSync == CheckSyncTrue && !b.opt.DryRun { + path1 := bilib.FsPath(b.fs1) + path2 := bilib.FsPath(b.fs2) + fs.Infof(nil, "Validating listings for Path1 %s vs Path2 %s", quotePath(path1), quotePath(path2)) + if err := b.checkSync(b.listing1, b.listing2); err != nil { + b.critical = true + return err + } + } + if !b.opt.NoCleanup { _ = os.Remove(b.newListing1) _ = os.Remove(b.newListing2) } return nil } + +/* + --resync-mode implementation: + PreferPath1: set ci.IgnoreExisting true, then false + PreferPath2: set ci.IgnoreExisting false, then true + PreferNewer: set ci.UpdateOlder in both directions + PreferOlder: override EqualFn to implement custom logic + PreferLarger: override EqualFn to implement custom logic + PreferSmaller: override EqualFn to implement custom logic +*/ +func (b *bisyncRun) setResyncConfig(ctx context.Context) context.Context { + ci := fs.GetConfig(ctx) + switch b.opt.ResyncMode { + case PreferPath1: + if !b.resyncIs1to2 { // 2to1 (remember 2to1 is first) + ci.IgnoreExisting = true + } else { // 1to2 + ci.IgnoreExisting = false + } + case PreferPath2: + if !b.resyncIs1to2 { // 2to1 (remember 2to1 is first) + ci.IgnoreExisting = false + } else { // 1to2 + ci.IgnoreExisting = true + } + case PreferNewer: + ci.UpdateOlder = true + } + // for older, larger, and smaller, we return it unchanged and handle it later + return ctx +} + +func (b *bisyncRun) resyncWhichIsWhich(src, dst fs.ObjectInfo) (path1, path2 fs.ObjectInfo) { + if b.resyncIs1to2 { + return src, dst + } + return dst, src +} + +// equal in this context really means "don't transfer", so we should +// return true if the files are actually equal or if dest is winner, +// false if src is winner +// When can't determine, we end up running the normal Equal() to tie-break (due to our differ functions). +func (b *bisyncRun) resyncWinningPathToEqual(winningPath int) bool { + if b.resyncIs1to2 { + return winningPath != 1 + } + return winningPath != 2 +} diff --git a/cmd/bisync/testdata/test_all_changed/golden/test.log b/cmd/bisync/testdata/test_all_changed/golden/test.log index f340d12c2..cb74904c9 100644 --- a/cmd/bisync/testdata/test_all_changed/golden/test.log +++ b/cmd/bisync/testdata/test_all_changed/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test change timestamp on all files except RCLONE_TEST diff --git a/cmd/bisync/testdata/test_backupdir/golden/test.log b/cmd/bisync/testdata/test_backupdir/golden/test.log index e398af723..cfd85b692 100644 --- a/cmd/bisync/testdata/test_backupdir/golden/test.log +++ b/cmd/bisync/testdata/test_backupdir/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test make modifications on both paths diff --git a/cmd/bisync/testdata/test_basic/golden/test.log b/cmd/bisync/testdata/test_basic/golden/test.log index d5f63b679..d3086e790 100644 --- a/cmd/bisync/testdata/test_basic/golden/test.log +++ b/cmd/bisync/testdata/test_basic/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test place newer files on both paths diff --git a/cmd/bisync/testdata/test_changes/golden/test.log b/cmd/bisync/testdata/test_changes/golden/test.log index 535042521..36aa3257c 100644 --- a/cmd/bisync/testdata/test_changes/golden/test.log +++ b/cmd/bisync/testdata/test_changes/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test make modifications on both paths diff --git a/cmd/bisync/testdata/test_check_access/golden/test.log b/cmd/bisync/testdata/test_check_access/golden/test.log index 7b6e19e88..4184a0f30 100644 --- a/cmd/bisync/testdata/test_check_access/golden/test.log +++ b/cmd/bisync/testdata/test_check_access/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test 1. see that check-access passes with the initial setup @@ -84,10 +85,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (13) : test 4. run sync with check-access. should pass. @@ -176,10 +178,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (24) : test 8. run sync with --check-access. should pass. diff --git a/cmd/bisync/testdata/test_check_access_filters/golden/test.log b/cmd/bisync/testdata/test_check_access_filters/golden/test.log index b9724a84f..eeb347438 100644 --- a/cmd/bisync/testdata/test_check_access_filters/golden/test.log +++ b/cmd/bisync/testdata/test_check_access_filters/golden/test.log @@ -19,10 +19,11 @@ INFO : Bisyncing with Comparison Settings: INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" INFO : Using filters file {workdir/}exclude-other-filtersfile.txt INFO : Storing filters file hash to {workdir/}exclude-other-filtersfile.txt.md5 -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (06) : test EXCLUDE - test filters for check access @@ -133,10 +134,11 @@ INFO : Bisyncing with Comparison Settings: INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" INFO : Using filters file {workdir/}include-other-filtersfile.txt INFO : Storing filters file hash to {workdir/}include-other-filtersfile.txt.md5 -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (29) : test INCLUDE - test include/exclude filters for check access diff --git a/cmd/bisync/testdata/test_check_filename/golden/test.log b/cmd/bisync/testdata/test_check_filename/golden/test.log index 59728701e..573976ede 100644 --- a/cmd/bisync/testdata/test_check_filename/golden/test.log +++ b/cmd/bisync/testdata/test_check_filename/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test 1. see that check-access passes with the initial setup @@ -85,12 +86,13 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 +INFO : Copying Path2 files to Path1 INFO : Checking access health INFO : Found 2 matching ".chk_file" files on both paths -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (14) : test 4. run sync with check-access. should pass. diff --git a/cmd/bisync/testdata/test_check_sync/golden/test.log b/cmd/bisync/testdata/test_check_sync/golden/test.log index 35246882d..46a5f0ffc 100644 --- a/cmd/bisync/testdata/test_check_sync/golden/test.log +++ b/cmd/bisync/testdata/test_check_sync/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test 1. run check-sync-only on a clean sync @@ -99,10 +100,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (20) : test 7. run normal sync with check-sync enabled (default) diff --git a/cmd/bisync/testdata/test_compare_all/golden/test.log b/cmd/bisync/testdata/test_compare_all/golden/test.log index 760cb69f6..9f78dbf82 100644 --- a/cmd/bisync/testdata/test_compare_all/golden/test.log +++ b/cmd/bisync/testdata/test_compare_all/golden/test.log @@ -13,10 +13,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": true } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test make modifications on both paths diff --git a/cmd/bisync/testdata/test_createemptysrcdirs/golden/test.log b/cmd/bisync/testdata/test_createemptysrcdirs/golden/test.log index 06dd5f2c6..096c5f0c5 100644 --- a/cmd/bisync/testdata/test_createemptysrcdirs/golden/test.log +++ b/cmd/bisync/testdata/test_createemptysrcdirs/golden/test.log @@ -21,10 +21,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (11) : test 1. Create an empty dir on Path1 by creating subdir/placeholder.txt and then deleting the placeholder @@ -144,10 +145,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (40) : list-dirs {path1/} subdir/ - filename hash: 86ae37b338459868804e9697025ba4c2 diff --git a/cmd/bisync/testdata/test_dry_run/golden/test.log b/cmd/bisync/testdata/test_dry_run/golden/test.log index 9b5f48d90..0eca08d1c 100644 --- a/cmd/bisync/testdata/test_dry_run/golden/test.log +++ b/cmd/bisync/testdata/test_dry_run/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test new on path2 - file10 @@ -65,12 +66,12 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 NOTICE: file10.txt: Skipped copy as --dry-run is set (size 19) NOTICE: file4.txt: Skipped copy as --dry-run is set (size 0) NOTICE: file6.txt: Skipped copy as --dry-run is set (size 19) -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : - Path1 Resync is copying files to - Path2 NOTICE: file1.txt: Skipped copy as --dry-run is set (size 0) NOTICE: file11.txt: Skipped copy as --dry-run is set (size 19) NOTICE: file2.txt: Skipped copy as --dry-run is set (size 13) diff --git a/cmd/bisync/testdata/test_equal/golden/test.log b/cmd/bisync/testdata/test_equal/golden/test.log index f52018acd..0a7f9ab34 100644 --- a/cmd/bisync/testdata/test_equal/golden/test.log +++ b/cmd/bisync/testdata/test_equal/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test changed on both paths and NOT identical - file1 (file1R, file1L) diff --git a/cmd/bisync/testdata/test_extended_char_paths/golden/test.log b/cmd/bisync/testdata/test_extended_char_paths/golden/test.log index ede7e1807..463e8e967 100644 --- a/cmd/bisync/testdata/test_extended_char_paths/golden/test.log +++ b/cmd/bisync/testdata/test_extended_char_paths/golden/test.log @@ -25,10 +25,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}測試_Русский_ _ _ě_áñ/" with Path2 "{path2/}測試_Русский_ _ _ě_áñ/" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}測試_Русский_ _ _ě_áñ/" vs Path2 "{path2/}測試_Русский_ _ _ě_áñ/" INFO : Bisync successful (14) : copy-listings resync @@ -81,10 +82,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (24) : delete-file {path1/}測試_Русский_{spc}_{spc}_ě_áñ/測試_check{spc}file (25) : bisync check-access check-filename=測試_check{spc}file @@ -125,10 +127,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (29) : bisync check-access check-filename=測試_check{spc}file INFO : Setting --ignore-listing-checksum as neither --checksum nor --compare checksum are set. @@ -169,10 +172,11 @@ INFO : Bisyncing with Comparison Settings: INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" INFO : Using filters file {workdir/}測試_filtersfile.txt INFO : Storing filters file hash to {workdir/}測試_filtersfile.txt.md5 -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (34) : copy-as {datadir/}file1.txt {path1/} fileZ.txt (35) : bisync filters-file={workdir/}測試_filtersfile.txt diff --git a/cmd/bisync/testdata/test_extended_filenames/golden/test.log b/cmd/bisync/testdata/test_extended_filenames/golden/test.log index 25bf9ea43..eda13848c 100644 --- a/cmd/bisync/testdata/test_extended_filenames/golden/test.log +++ b/cmd/bisync/testdata/test_extended_filenames/golden/test.log @@ -23,10 +23,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (12) : test place a newer files on both paths diff --git a/cmd/bisync/testdata/test_filters/golden/test.log b/cmd/bisync/testdata/test_filters/golden/test.log index c43a9beb5..9da9b2130 100644 --- a/cmd/bisync/testdata/test_filters/golden/test.log +++ b/cmd/bisync/testdata/test_filters/golden/test.log @@ -18,10 +18,11 @@ INFO : Bisyncing with Comparison Settings: INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" INFO : Using filters file {workdir/}filtersfile.flt INFO : Storing filters file hash to {workdir/}filtersfile.flt.md5 -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (05) : copy-listings resync diff --git a/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log b/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log index 5d15dbe36..a60aa5d49 100644 --- a/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log +++ b/cmd/bisync/testdata/test_filtersfile_checks/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test 1. inject filters file in workdir. @@ -78,10 +79,11 @@ INFO : Bisyncing with Comparison Settings: INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" INFO : Using filters file {workdir/}filtersfile.txt INFO : Storing filters file hash to {workdir/}filtersfile.txt.md5 -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (12) : test 5. run with filters-file alone. should run. @@ -142,9 +144,9 @@ INFO : Bisyncing with Comparison Settings: 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 : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings INFO : Bisync successful diff --git a/cmd/bisync/testdata/test_ignorelistingchecksum/golden/test.log b/cmd/bisync/testdata/test_ignorelistingchecksum/golden/test.log index fc6fc4e8f..f54cd7baf 100644 --- a/cmd/bisync/testdata/test_ignorelistingchecksum/golden/test.log +++ b/cmd/bisync/testdata/test_ignorelistingchecksum/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : bisync resync ignore-listing-checksum INFO : Bisyncing with Comparison Settings: @@ -30,10 +31,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (05) : test place newer files on both paths diff --git a/cmd/bisync/testdata/test_max_delete_path1/golden/test.log b/cmd/bisync/testdata/test_max_delete_path1/golden/test.log index 877b48f0a..42aff09c0 100644 --- a/cmd/bisync/testdata/test_max_delete_path1/golden/test.log +++ b/cmd/bisync/testdata/test_max_delete_path1/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test delete >50% of local files diff --git a/cmd/bisync/testdata/test_max_delete_path2_force/golden/test.log b/cmd/bisync/testdata/test_max_delete_path2_force/golden/test.log index d6efc5981..1cc290994 100644 --- a/cmd/bisync/testdata/test_max_delete_path2_force/golden/test.log +++ b/cmd/bisync/testdata/test_max_delete_path2_force/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test delete >50% of remote files diff --git a/cmd/bisync/testdata/test_normalization/golden/test.log b/cmd/bisync/testdata/test_normalization/golden/test.log index c8c0f2a6d..5e4cbbccf 100644 --- a/cmd/bisync/testdata/test_normalization/golden/test.log +++ b/cmd/bisync/testdata/test_normalization/golden/test.log @@ -15,10 +15,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful @@ -93,10 +94,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful @@ -166,10 +168,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (29) : test changed on one path diff --git a/cmd/bisync/testdata/test_rclone_args/golden/test.log b/cmd/bisync/testdata/test_rclone_args/golden/test.log index 10819ff05..73ede1e69 100644 --- a/cmd/bisync/testdata/test_rclone_args/golden/test.log +++ b/cmd/bisync/testdata/test_rclone_args/golden/test.log @@ -13,10 +13,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": true } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test place newer files on both paths @@ -104,10 +105,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (19) : copy-file {datadir/}file1.txt {path1/} @@ -154,10 +156,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": true } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (25) : copy-as {datadir/}file21.txt {path2/} file2.txt diff --git a/cmd/bisync/testdata/test_resolve/golden/test.log b/cmd/bisync/testdata/test_resolve/golden/test.log index a8e129259..9223c3f6a 100644 --- a/cmd/bisync/testdata/test_resolve/golden/test.log +++ b/cmd/bisync/testdata/test_resolve/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test changed on both paths and NOT identical - file1 (file1R, file1L) @@ -282,8 +283,8 @@ INFO : Path2: 2 changes:  1 new,  1 modified,  INFO : (Modified:  1 newer,  0 older,  1 larger,  0 smaller) INFO : Applying changes INFO : Checking potential conflicts... -ERROR : file1.txt: md5 differ ERROR : file2.txt: md5 differ +ERROR : file1.txt: md5 differ NOTICE: {path2String}: 2 differences found NOTICE: {path2String}: 2 errors while checking INFO : Finished checking the potential conflicts. 2 differences found diff --git a/cmd/bisync/testdata/test_resync/golden/test.log b/cmd/bisync/testdata/test_resync/golden/test.log index 9c7164f85..f9488a672 100644 --- a/cmd/bisync/testdata/test_resync/golden/test.log +++ b/cmd/bisync/testdata/test_resync/golden/test.log @@ -15,10 +15,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (05) : move-listings empty-path1 @@ -36,10 +37,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (09) : move-listings empty-path2 @@ -83,10 +85,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (31) : copy-listings mixed-diffs diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst new file mode 100644 index 000000000..b0d680388 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst @@ -0,0 +1,4 @@ +# bisync listing v1 from test +- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 42 - - 2022-02-22T00:00:00.000000000+0000 "file1.txt" +- 33 - - 2022-02-22T00:00:00.000000000+0000 "file2.txt" diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-new b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-new new file mode 100644 index 000000000..4f98654dc --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-new @@ -0,0 +1 @@ +# bisync listing v1 from test diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-old b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-old new file mode 100644 index 000000000..75d37f056 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path1.lst-old @@ -0,0 +1,4 @@ +# 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" +- 42 - - 2005-01-02T00:00:00.000000000+0000 "file2.txt" diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst new file mode 100644 index 000000000..b0d680388 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst @@ -0,0 +1,4 @@ +# bisync listing v1 from test +- 109 - - 2000-01-01T00:00:00.000000000+0000 "RCLONE_TEST" +- 42 - - 2022-02-22T00:00:00.000000000+0000 "file1.txt" +- 33 - - 2022-02-22T00:00:00.000000000+0000 "file2.txt" diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-new b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-new new file mode 100644 index 000000000..4f98654dc --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-new @@ -0,0 +1 @@ +# bisync listing v1 from test diff --git a/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-old b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-old new file mode 100644 index 000000000..75d37f056 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/_testdir_path1.._testdir_path2.path2.lst-old @@ -0,0 +1,4 @@ +# 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" +- 42 - - 2005-01-02T00:00:00.000000000+0000 "file2.txt" diff --git a/cmd/bisync/testdata/test_resync_modes/golden/test.log b/cmd/bisync/testdata/test_resync_modes/golden/test.log new file mode 100644 index 000000000..017822aa2 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/golden/test.log @@ -0,0 +1,192 @@ +(01) : test resync-mode + + +(02) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(03) : touch-glob 2001-01-02 {datadir/} file1R.txt +(04) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(05) : touch-glob 2001-03-04 {datadir/} file1L.txt +(06) : copy-as {datadir/}file1L.txt {path1/} file1.txt + +(07) : test bisync run with --resync-mode=newer +(08) : bisync resync resync-mode=newer +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(09) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(10) : touch-glob 2001-07-23 {datadir/} file1R.txt +(11) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(12) : touch-glob 2001-08-26 {datadir/} file1L.txt +(13) : copy-as {datadir/}file1L.txt {path1/} file1.txt + +(14) : test bisync run with --resync-mode=path2 +(15) : bisync resync resync-mode=path2 +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(16) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(17) : touch-glob 2002-07-23 {datadir/} file1R.txt +(18) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(19) : touch-glob 2002-08-26 {datadir/} file1L.txt +(20) : copy-as {datadir/}file1L.txt {path1/} file1.txt + +(21) : test bisync run with --resync-mode=larger +(22) : bisync resync resync-mode=larger +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : file1.txt: Path2 is larger. Path1: 33, Path2: 42, Difference: 9 +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(23) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(24) : touch-glob 2003-07-23 {datadir/} file1R.txt +(25) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(26) : touch-glob 2003-09-04 {datadir/} file1L.txt +(27) : copy-as {datadir/}file1L.txt {path1/} file1.txt + +(28) : test bisync run with --resync-mode=older +(29) : bisync resync resync-mode=older +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : file1.txt: Path2 is older. Path1: 2003-09-03 20:00:00 -0400 EDT, Path2: 2003-07-22 20:00:00 -0400 EDT, Difference: 1032h0m0s +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(30) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(31) : touch-glob 2004-07-23 {datadir/} file1R.txt +(32) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(33) : touch-glob 2004-07-23 {datadir/} file1L.txt +(34) : copy-as {datadir/}file1L.txt {path1/} file1.txt + +(35) : test bisync run with --resync-mode=smaller +(36) : bisync resync resync-mode=smaller +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : file1.txt: Path1 is smaller. Path1: 33, Path2: 42, Difference: 9 +INFO : - Path1 Resync is copying files to - Path2 +INFO : file1.txt: Path1 is smaller. Path1: 33, Path2: 42, Difference: 9 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(37) : test changed on both paths and NOT identical - file1 (file1R, file1L) +(38) : touch-glob 2005-01-02 {datadir/} file1R.txt +(39) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(40) : copy-as {datadir/}file1R.txt {path1/} file2.txt +(41) : touch-glob 2006-03-04 {datadir/} file1L.txt +(42) : copy-as {datadir/}file1L.txt {path1/} file1.txt +(43) : copy-as {datadir/}file1L.txt {path2/} file2.txt + +(44) : test bisync run with --resync-mode=path1 +(45) : bisync resync resync-mode=path1 +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful + +(46) : test no winner +(47) : touch-glob 2022-02-22 {datadir/} file1R.txt +(48) : copy-as {datadir/}file1R.txt {path2/} file1.txt +(49) : copy-as {datadir/}file1R.txt {path1/} file2.txt +(50) : touch-glob 2022-02-22 {datadir/} file1L.txt +(51) : copy-as {datadir/}file1L.txt {path1/} file1.txt +(52) : copy-as {datadir/}file1L.txt {path2/} file2.txt + +(53) : test bisync run with --resync-mode=newer +(54) : bisync resync resync-mode=newer +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 : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 +INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" +INFO : Bisync successful diff --git a/cmd/bisync/testdata/test_resync_modes/initial/RCLONE_TEST b/cmd/bisync/testdata/test_resync_modes/initial/RCLONE_TEST new file mode 100644 index 000000000..d8ca97c2a --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/initial/RCLONE_TEST @@ -0,0 +1 @@ +This file is used for testing the health of rclone accesses to the local/remote file system. Do not delete. diff --git a/cmd/bisync/testdata/test_resync_modes/initial/file1.txt b/cmd/bisync/testdata/test_resync_modes/initial/file1.txt new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/bisync/testdata/test_resync_modes/initial/file2.txt b/cmd/bisync/testdata/test_resync_modes/initial/file2.txt new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/bisync/testdata/test_resync_modes/modfiles/file1L.txt b/cmd/bisync/testdata/test_resync_modes/modfiles/file1L.txt new file mode 100644 index 000000000..6906ccb09 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/modfiles/file1L.txt @@ -0,0 +1 @@ +This file is NOT identical to 1R diff --git a/cmd/bisync/testdata/test_resync_modes/modfiles/file1R.txt b/cmd/bisync/testdata/test_resync_modes/modfiles/file1R.txt new file mode 100644 index 000000000..1e3eb3f77 --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/modfiles/file1R.txt @@ -0,0 +1 @@ +This file is NOT identical to 1L (LARGER) diff --git a/cmd/bisync/testdata/test_resync_modes/modfiles/file2.txt b/cmd/bisync/testdata/test_resync_modes/modfiles/file2.txt new file mode 100644 index 000000000..2ee5fc1ee --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/modfiles/file2.txt @@ -0,0 +1 @@ +This file is identical on both sides diff --git a/cmd/bisync/testdata/test_resync_modes/scenario.txt b/cmd/bisync/testdata/test_resync_modes/scenario.txt new file mode 100644 index 000000000..51ca567fc --- /dev/null +++ b/cmd/bisync/testdata/test_resync_modes/scenario.txt @@ -0,0 +1,70 @@ +test resync-mode +# Check conflict-resolution options during resync +# - Changed on Path2 and on Path1, and NOT identical file1 (file1r, file1l) + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2001-01-02 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +touch-glob 2001-03-04 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt + +test bisync run with --resync-mode=newer +bisync resync resync-mode=newer + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2001-07-23 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +touch-glob 2001-08-26 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt + +test bisync run with --resync-mode=path2 +bisync resync resync-mode=path2 + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2002-07-23 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +touch-glob 2002-08-26 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt + +test bisync run with --resync-mode=larger +bisync resync resync-mode=larger + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2003-07-23 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +touch-glob 2003-09-04 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt + +test bisync run with --resync-mode=older +bisync resync resync-mode=older + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2004-07-23 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +touch-glob 2004-07-23 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt + +test bisync run with --resync-mode=smaller +bisync resync resync-mode=smaller + +test changed on both paths and NOT identical - file1 (file1R, file1L) +touch-glob 2005-01-02 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +copy-as {datadir/}file1R.txt {path1/} file2.txt +touch-glob 2006-03-04 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt +copy-as {datadir/}file1L.txt {path2/} file2.txt + +test bisync run with --resync-mode=path1 +bisync resync resync-mode=path1 + +test no winner +touch-glob 2022-02-22 {datadir/} file1R.txt +copy-as {datadir/}file1R.txt {path2/} file1.txt +copy-as {datadir/}file1R.txt {path1/} file2.txt +touch-glob 2022-02-22 {datadir/} file1L.txt +copy-as {datadir/}file1L.txt {path1/} file1.txt +copy-as {datadir/}file1L.txt {path2/} file2.txt + +test bisync run with --resync-mode=newer +bisync resync resync-mode=newer \ No newline at end of file diff --git a/cmd/bisync/testdata/test_rmdirs/golden/test.log b/cmd/bisync/testdata/test_rmdirs/golden/test.log index b5e47b879..4e6763801 100644 --- a/cmd/bisync/testdata/test_rmdirs/golden/test.log +++ b/cmd/bisync/testdata/test_rmdirs/golden/test.log @@ -14,10 +14,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test 1. delete path1 subdir file diff --git a/cmd/bisync/testdata/test_volatile/golden/test.log b/cmd/bisync/testdata/test_volatile/golden/test.log index d8af65a78..ab3003a76 100644 --- a/cmd/bisync/testdata/test_volatile/golden/test.log +++ b/cmd/bisync/testdata/test_volatile/golden/test.log @@ -13,10 +13,11 @@ INFO : Bisyncing with Comparison Settings: "DownloadHash": false } INFO : Synching Path1 "{path1/}" with Path2 "{path2/}" -INFO : Copying unique Path2 files to Path1 -INFO : - Path2 Resync is copying UNIQUE files to - Path1 -INFO : - Path1 Resync is copying UNIQUE OR DIFFERING files to - Path2 +INFO : Copying Path2 files to Path1 +INFO : - Path2 Resync is copying files to - Path1 +INFO : - Path1 Resync is copying files to - Path2 INFO : Resync updating listings +INFO : Validating listings for Path1 "{path1/}" vs Path2 "{path2/}" INFO : Bisync successful (04) : test changed on both paths - file5 (file5R, file5L) diff --git a/docs/content/bisync.md b/docs/content/bisync.md index a4ac4772c..461ac604f 100644 --- a/docs/content/bisync.md +++ b/docs/content/bisync.md @@ -159,10 +159,10 @@ as the last step in the process. ### --resync This will effectively make both Path1 and Path2 filesystems contain a -matching superset of all files. Path2 files that do not exist in Path1 will +matching superset of all files. By default, Path2 files that do not exist in Path1 will be copied to Path1, and the process will then copy the Path1 tree to Path2. -The `--resync` sequence is roughly equivalent to: +The `--resync` sequence is roughly equivalent to the following (but see [`--resync-mode`](#resync-mode) for other options): ``` rclone copy Path2 Path1 --ignore-existing [--create-empty-src-dirs] rclone copy Path1 Path2 [--create-empty-src-dirs] @@ -173,8 +173,8 @@ or bisync will fail. This is required for safety - that bisync can verify that both paths are valid. When using `--resync`, a newer version of a file on the Path2 filesystem -will be overwritten by the Path1 filesystem version. -(Note that this is [NOT entirely symmetrical](https://github.com/rclone/rclone/issues/5681#issuecomment-938761815).) +will (by default) be overwritten by the Path1 filesystem version. +(Note that this is [NOT entirely symmetrical](https://github.com/rclone/rclone/issues/5681#issuecomment-938761815), and more symmetrical options can be specified with the [`--resync-mode`](#resync-mode) flag.) Carefully evaluate deltas using [--dry-run](/flags/#non-backend-flags). For a resync run, one of the paths may be empty (no files in the path tree). @@ -186,7 +186,12 @@ For a non-resync run, either path being empty (no files in the tree) fails with This is a safety check that an unexpected empty path does not result in deleting **everything** in the other path. -**Note:** `--resync` should only be used under three specific (rare) circumstances: +Note that `--resync` implies `--resync-mode path1` unless a different +[`--resync-mode`](#resync-mode) is explicitly specified. +It is not necessary to use both the `--resync` and `--resync-mode` flags -- +either one is sufficient without the other. + +**Note:** `--resync` (including `--resync-mode`) should only be used under three specific (rare) circumstances: 1. It is your _first_ bisync run (between these two paths) 2. You've just made changes to your bisync settings (such as editing the contents of your `--filters-file`) 3. There was an error on the prior run, and as a result, bisync now requires `--resync` to recover @@ -196,6 +201,84 @@ Therefore, if you included `--resync` for every bisync run, it would never be po the deleted file would always keep reappearing at the end of every run (because it's being copied from the other side where it still exists). Similarly, renaming a file would always result in a duplicate copy (both old and new name) on both sides. +If you find that frequent interruptions from #3 are an issue, rather than +automatically running `--resync`, the recommended alternative is to use the +[`--resilient`](#resilient), [`--recover`](#recover), and +[`--conflict-resolve`](#conflict-resolve) flags, (along with [Graceful +Shutdown](#graceful-shutdown) mode, when needed) for a very robust +"set-it-and-forget-it" bisync setup that can automatically bounce back from +almost any interruption it might encounter. Consider adding something like the +following: + +``` +--resilient --recover --max-lock 2m --conflict-resolve newer +``` + +### --resync-mode CHOICE {#resync-mode} + +In the event that a file differs on both sides during a `--resync`, +`--resync-mode` controls which version will overwrite the other. The supported +options are similar to [`--conflict-resolve`](#conflict-resolve). For all of +the following options, the version that is kept is referred to as the "winner", +and the version that is overwritten (deleted) is referred to as the "loser". +The options are named after the "winner": + +- `path1` - (the default) - the version from Path1 is unconditionally +considered the winner (regardless of `modtime` and `size`, if any). This can be +useful if one side is more trusted or up-to-date than the other, at the time of +the `--resync`. +- `path2` - same as `path1`, except the path2 version is considered the winner. +- `newer` - the newer file (by `modtime`) is considered the winner, regardless +of which side it came from. This may result in having a mix of some winners +from Path1, and some winners from Path2. (The implementation is analagous to +running `rclone copy --update` in both directions.) +- `older` - same as `newer`, except the older file is considered the winner, +and the newer file is considered the loser. +- `larger` - the larger file (by `size`) is considered the winner (regardless +of `modtime`, if any). This can be a useful option for remotes without +`modtime` support, or with the kinds of files (such as logs) that tend to grow +but not shrink, over time. +- `smaller` - the smaller file (by `size`) is considered the winner (regardless +of `modtime`, if any). + +For all of the above options, note the following: +- If either of the underlying remotes lacks support for the chosen method, it +will be ignored and will fall back to the default of `path1`. (For example, if +`--resync-mode newer` is set, but one of the paths uses a remote that doesn't +support `modtime`.) +- If a winner can't be determined because the chosen method's attribute is +missing or equal, it will be ignored, and bisync will instead try to determine +whether the files differ by looking at the other `--compare` methods in effect. +(For example, if `--resync-mode newer` is set, but the Path1 and Path2 modtimes +are identical, bisync will compare the sizes.) If bisync concludes that they +differ, preference is given to whichever is the "source" at that moment. (In +practice, this gives a slight advantage to Path2, as the 2to1 copy comes before +the 1to2 copy.) If the files _do not_ differ, nothing is copied (as both sides +are already correct). +- These options apply only to files that exist on both sides (with the same +name and relative path). Files that exist *only* on one side and not the other +are *always* copied to the other, during `--resync` (this is one of the main +differences between resync and non-resync runs.). +- `--conflict-resolve`, `--conflict-loser`, and `--conflict-suffix` do not +apply during `--resync`, and unlike these flags, nothing is renamed during +`--resync`. When a file differs on both sides during `--resync`, one version +always overwrites the other (much like in `rclone copy`.) (Consider using +[`--backup-dir`](#backup-dir1-and-backup-dir2) to retain a backup of the losing +version.) +- Unlike for `--conflict-resolve`, `--resync-mode none` is not a valid option +(or rather, it will be interpreted as "no resync", unless `--resync` has also +been specified, in which case it will be ignored.) +- Winners and losers are decided at the individual file-level only (there is +not currently an option to pick an entire winning directory atomically, +although the `path1` and `path2` options typically produce a similar result.) +- To maintain backward-compatibility, the `--resync` flag implies +`--resync-mode path1` unless a different `--resync-mode` is explicitly +specified. Similarly, all `--resync-mode` options (except `none`) imply +`--resync`, so it is not necessary to use both the `--resync` and +`--resync-mode` flags simultaneously -- either one is sufficient without the +other. + + ### --check-access Access check files are an additional safety measure against data loss. @@ -1752,6 +1835,7 @@ instead of of `--size-only`, when `check` is not available. * New `--recover` flag allows robust recovery in the event of interruptions, without requiring `--resync`. * A new `--max-lock` setting allows lock files to automatically renew and expire, for better automatic recovery when a run is interrupted. * Bisync now supports auto-resolving sync conflicts and customizing rename behavior with new [`--conflict-resolve`](#conflict-resolve), [`--conflict-loser`](#conflict-loser), and [`--conflict-suffix`](#conflict-suffix) flags. +* A new [`--resync-mode`](#resync-mode) flag allows more control over which version of a file gets kept during a `--resync`. ### `v1.64` * Fixed an [issue](https://forum.rclone.org/t/bisync-bugs-and-feature-requests/37636#:~:text=1.%20Dry%20runs%20are%20not%20completely%20dry)