From 69ff0092644b9bf2e1e568fb073f8e6127aa13cf Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 6 Jul 2017 14:07:26 +0100 Subject: [PATCH] Use a stable sort for sorting directory entries This is useful if 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 consistently use the first entry for the sync comparison. --- fs/operations.go | 10 ++++++++-- fs/walk.go | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) 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