From 7a11489e3d8f9d705dbc852573df2f44f3ac8837 Mon Sep 17 00:00:00 2001 From: yourok <8yourok8@mail.ru> Date: Sat, 22 Dec 2018 14:33:41 +0300 Subject: [PATCH] fix sort/id bug --- src/server/torr/Torrent.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/server/torr/Torrent.go b/src/server/torr/Torrent.go index 5c5dd49..aa236d2 100644 --- a/src/server/torr/Torrent.go +++ b/src/server/torr/Torrent.go @@ -385,16 +385,19 @@ func (t *Torrent) Stats() TorrentStats { st.ConnectedSeeders = tst.ConnectedSeeders st.HalfOpenPeers = tst.HalfOpenPeers - for i, f := range t.Files() { + files := t.Files() + + sort.Slice(files, func(i, j int) bool { + return files[i].Path() < files[j].Path() + }) + + for i, f := range files { st.FileStats = append(st.FileStats, TorrentFileStat{ Id: i, Path: f.Path(), Length: f.Length(), }) } - sort.Slice(st.FileStats, func(i, j int) bool { - return st.FileStats[i].Path < st.FileStats[j].Path - }) } return st }