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

Use a stable sort for sorting directory entries

Nick Craig-Wood69ff0092644b
diff --git a/fs/operations.go b/fs/operations.go
index a7b7c0640..ebbfe1ed6 100644
--- a/fs/operations.go
+++ b/fs/operations.go
@@ -630,8 +630,14 @@ func ListDirSorted(fs Fs, includeAll bool, dir string) (entries DirEntries, err
entries = newEntries
}
- // sort the directory entries by Remote
- sort.Sort(entries)
+ // Sort the directory entries by Remote
+ //
+ // We use a stable sort here just in case there are
+ // duplicates. Assuming the remote delivers the entries in a
+ // consistent order, this will give the best user experience
+ // in syncing as it will use the first entry for the sync
+ // comparison.
+ sort.Stable(entries)
return entries, nil
}
diff --git a/fs/walk.go b/fs/walk.go
index 7193c5590..ee5268cbf 100644
--- a/fs/walk.go
+++ b/fs/walk.go
@@ -229,7 +229,7 @@ func (dt DirTree) checkParents(root string) {
// Sort sorts all the Entries
func (dt DirTree) Sort() {
for _, entries := range dt {
- sort.Sort(entries)
+ sort.Stable(entries)
}
}
@@ -342,7 +342,6 @@ func walkR(f Fs, path string, includeAll bool, maxLevel int, fn WalkFunc, listR
if entries == nil {
entries = emptyDir
}
- sort.Sort(entries)
err = fn(dirPath, entries, nil)
if err == ErrorSkipDir {
skipping = true