"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
bisync: fix listings ignoring a modtime less than 1s older
nielash17df19341a9b
diff --git a/cmd/bisync/listing.go b/cmd/bisync/listing.goindex f5fc54efb..99f7fe62f 100644--- a/cmd/bisync/listing.go+++ b/cmd/bisync/listing.go@@ -129,12 +129,6 @@ func (ls *fileList) put(file string, size int64, modtime time.Time, hash, id strfi := ls.get(file)if fi != nil {fi.size = size- // if already have higher precision of same time, avoid overwriting it- if fi.time != modtime {- if modtime.Before(fi.time) && fi.time.Sub(modtime) < time.Second {- modtime = fi.time- }- }fi.time = modtimefi.hash = hashfi.id = iddiff --git a/cmd/bisync/listing_internal_test.go b/cmd/bisync/listing_internal_test.gonew file mode 100644index 000000000..411fe6edd--- /dev/null+++ b/cmd/bisync/listing_internal_test.go@@ -0,0 +1,114 @@+package bisync++import (+ "context"+ "os"+ "path/filepath"+ "strings"+ "testing"+ "time"++ "github.com/rclone/rclone/fs"+ "github.com/rclone/rclone/fstest"+ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++func TestFileListPut(t *testing.T) {+ old := time.Date(2026, 9, 29, 12, 0, 1, 555555555, time.UTC)+ for _, test := range []struct {+ name string+ modtime time.Time+ }{+ {"slightly older", old.Add(-124 * time.Microsecond)},+ {"slightly newer", old.Add(124 * time.Microsecond)},+ {"same second, truncated", old.Truncate(time.Second)},+ {"same second, rounded up", old.Round(time.Second)},+ } {+ t.Run(test.name, func(t *testing.T) {+ ls := newFileList()+ ls.put("file", 1, old, "", "-", "-")+ ls.put("file", 2, test.modtime, "", "-", "-")+ assert.True(t, test.modtime.Equal(ls.getTime("file")), "got %v, want %v", ls.getTime("file"), test.modtime)+ assert.EqualValues(t, 2, ls.getSize("file"))+ })+ }+}++// Test a file whose new version is less than a second older than the old one+func TestBisyncCloseModtimes(t *testing.T) {+ if *fstest.RemoteName != "" {+ t.Skip("Skipping test on non local remote")+ }+ ctx := context.Background()+ unchanged := time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)+ newRun := func(t *testing.T) (path1, path2 string, run func(resync bool) error) {+ // t.TempDir includes the test name, which makes the listing names too long+ dir, err := os.MkdirTemp("", "bisync")+ require.NoError(t, err)+ t.Cleanup(func() { _ = os.RemoveAll(dir) })+ path1, path2 = filepath.Join(dir, "path1"), filepath.Join(dir, "path2")+ workdir := filepath.Join(dir, "workdir")+ for _, path := range []string{path1, path2} {+ require.NoError(t, os.Mkdir(path, 0o755))+ require.NoError(t, os.WriteFile(filepath.Join(path, "file1.txt"), []byte("unchanged"), 0o644))+ require.NoError(t, os.Chtimes(filepath.Join(path, "file1.txt"), unchanged, unchanged))+ }+ run = func(resync bool) error {+ f1, err := fs.NewFs(ctx, path1)+ require.NoError(t, err)+ f2, err := fs.NewFs(ctx, path2)+ require.NoError(t, err)+ return Bisync(ctx, f1, f2, &Options{Workdir: workdir, Resync: resync, CheckSync: CheckSyncTrue, MaxDelete: DefaultMaxDelete})+ }+ return path1, path2, run+ }+ writeFile := func(t *testing.T, path, content string, modtime time.Time) {+ file := filepath.Join(path, "file0.txt")+ require.NoError(t, os.WriteFile(file, []byte(content), 0o644))+ require.NoError(t, os.Chtimes(file, modtime, modtime))+ }+ // listingTime returns the modtime recorded for file0.txt in the listing for path (1 or 2)+ listingTime := func(t *testing.T, path1 string, path int) time.Time {+ listings, err := filepath.Glob(filepath.Join(filepath.Dir(path1), "workdir", "*.path"+string(rune('0'+path))+".lst"))+ require.NoError(t, err)+ require.Len(t, listings, 1)+ data, err := os.ReadFile(listings[0])+ require.NoError(t, err)+ for line := range strings.SplitSeq(string(data), "\n") {+ if strings.HasSuffix(line, `"file0.txt"`) {+ fields := strings.Fields(line)+ modtime, err := time.Parse(timeFormat, fields[4])+ require.NoError(t, err)+ return modtime+ }+ }+ t.Fatal("file0.txt not in listing")+ return time.Time{}+ }+ // fileTime returns file0.txt's modtime as the filesystem stored it (Windows keeps 100ns)+ fileTime := func(t *testing.T, path string) time.Time {+ info, err := os.Stat(filepath.Join(path, "file0.txt"))+ require.NoError(t, err)+ return info.ModTime()+ }+ modtime := time.Date(2026, 9, 29, 12, 0, 1, 555555555, time.UTC)++ t.Run("resync", func(t *testing.T) {+ path1, path2, run := newRun(t)+ writeFile(t, path1, "path1", modtime)+ writeFile(t, path2, "path2, newer", modtime.Add(124*time.Microsecond))+ require.NoError(t, run(true))+ assert.True(t, fileTime(t, path2).Equal(listingTime(t, path1, 2)), "Path2 listing has %v, file has %v", listingTime(t, path1, 2), fileTime(t, path2))+ })++ t.Run("older edit", func(t *testing.T) {+ path1, path2, run := newRun(t)+ writeFile(t, path1, "original", modtime)+ require.NoError(t, run(true))+ writeFile(t, path1, "edited", modtime.Add(-200*time.Microsecond))+ require.NoError(t, run(false))+ assert.True(t, fileTime(t, path1).Equal(listingTime(t, path1, 1)), "Path1 listing has %v, file has %v", listingTime(t, path1, 1), fileTime(t, path1))+ assert.True(t, fileTime(t, path2).Equal(listingTime(t, path1, 2)), "Path2 listing has %v, file has %v", listingTime(t, path1, 2), fileTime(t, path2))+ })+}diff --git a/docs/content/bisync.md b/docs/content/bisync.mdindex 737397827..330ff0c20 100644--- a/docs/content/bisync.md+++ b/docs/content/bisync.md@@ -1944,6 +1944,9 @@ Path2 won.- When a file changed on both sides has an unexpectedly blank hash (for example,an S3 multipart object without an MD5), bisync now compares it by downloadingit, as with `--download`, instead of by size alone.+- Fixed an issue causing a `--resync` to fail with "path1 and path2 are out of+sync", or later runs to report changes that didn't happen, when a file's new+modtime was less than a second earlier than the one in the listing.### `v1.74.2`