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

march: fix syncing with a duplicate file and directory

Nick Craig-Wood5173ca045455
diff --git a/fs/march/march.go b/fs/march/march.go
index a879871af..578aea512 100644
--- a/fs/march/march.go
+++ b/fs/march/march.go
@@ -89,6 +89,13 @@ func (m *March) key(entry fs.DirEntry) string {
for _, transform := range m.transforms {
name = transform(name)
}
+ // Suffix entries to make identically named files and
+ // directories sort consistently with directories first.
+ if _, isDirectory := entry.(fs.Directory); isDirectory {
+ name += "D"
+ } else {
+ name += "F"
+ }
return name
}
diff --git a/fs/march/march_test.go b/fs/march/march_test.go
index 2d1d03e74..ad71e6dd3 100644
--- a/fs/march/march_test.go
+++ b/fs/march/march_test.go
@@ -477,6 +477,17 @@ func TestMatchListings(t *testing.T) {
{dirA, dirA},
},
},
+ {
+ what: "Sync with duplicate files and dirs",
+ input: fs.DirEntries{
+ dirA, A,
+ A, dirA,
+ },
+ matches: []matchPair{
+ {dirA, dirA},
+ {A, A},
+ },
+ },
} {
t.Run(fmt.Sprintf("TestMatchListings-%s", test.what), func(t *testing.T) {
ctx := context.Background()