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.
This commit is contained in:
Nick Craig-Wood 2017-07-06 14:07:26 +01:00
parent 27b157580e
commit 69ff009264
2 changed files with 9 additions and 4 deletions

View File

@ -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
}

View File

@ -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