From 8ce61e911de9126a078b2f2826cc2db747994ec7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 21 Jul 2015 22:54:02 +1000 Subject: [PATCH] Torrent.BytesCompleted was racy --- client.go | 2 +- t.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index aaa2ee4d..8621d164 100644 --- a/client.go +++ b/client.go @@ -1979,7 +1979,7 @@ func (t *torrent) addTrackers(announceList [][]string) { } // Don't call this before the info is available. -func (t *torrent) BytesCompleted() int64 { +func (t *torrent) bytesCompleted() int64 { if !t.haveInfo() { return 0 } diff --git a/t.go b/t.go index 41925860..8a561661 100644 --- a/t.go +++ b/t.go @@ -52,3 +52,9 @@ func (t Torrent) Drop() { t.cl.dropTorrent(t.InfoHash) t.cl.mu.Unlock() } + +func (t Torrent) BytesCompleted() int64 { + t.cl.mu.RLock() + defer t.cl.mu.RUnlock() + return t.bytesCompleted() +}