From 433b73a5a863ea366958e4400aa37b6be4431ac0 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 18 Sep 2020 12:30:01 +0100 Subject: [PATCH] accounting: stabilize display order of transfers on Windows Before this change we sorted transfers in the stats list solely on time started. However if --check-first was in use then lots of transfers could be started in the same millisecond. Because Windows time resolution is only 1mS this caused the entries to sort equal and bounce around in the list. This change fixes the sort so that if the time is equal it uses the name which should stabilize the order. Fixes #4599 --- fs/accounting/transfermap.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/accounting/transfermap.go b/fs/accounting/transfermap.go index ce145ae38..a9b9c6700 100644 --- a/fs/accounting/transfermap.go +++ b/fs/accounting/transfermap.go @@ -72,8 +72,16 @@ func (tm *transferMap) _sortedSlice() []*Transfer { for _, tr := range tm.items { s = append(s, tr) } + // sort by time first and if equal by name. Note that the relatively + // low time resolution on Windows can cause equal times. sort.Slice(s, func(i, j int) bool { - return s[i].startedAt.Before(s[j].startedAt) + a, b := s[i], s[j] + if a.startedAt.Before(b.startedAt) { + return true + } else if !a.startedAt.Equal(b.startedAt) { + return false + } + return a.remote < b.remote }) return s }