From: Matt Joiner <anacrolix@gmail.com>
Date: Sun, 21 Feb 2016 06:24:59 +0000 (+1100)
Subject: Refresh all piece completion states when data is missing
X-Git-Tag: v1.0.0~871
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=5b443fb63d8ea42b9826b64456d92d2bf298038c;p=btrtrc.git

Refresh all piece completion states when data is missing
---

diff --git a/reader.go b/reader.go
index 0f92343a..f0b81668 100644
--- a/reader.go
+++ b/reader.go
@@ -136,8 +136,8 @@ func (r *Reader) readOnceAt(b []byte, pos int64) (n int, err error) {
 		}
 		log.Printf("%s: error reading from torrent storage pos=%d: %s", r.t, pos, err)
 		r.t.cl.mu.Lock()
-		r.t.torrent.updatePieceCompletion(pi)
-		r.t.torrent.updatePiecePriority(pi)
+		r.t.torrent.updateAllPieceCompletions()
+		r.t.torrent.updatePiecePriorities()
 		r.t.cl.mu.Unlock()
 	}
 }
diff --git a/torrent.go b/torrent.go
index daca65c0..3bbbcef8 100644
--- a/torrent.go
+++ b/torrent.go
@@ -17,6 +17,7 @@ import (
 	"github.com/anacrolix/missinggo/itertools"
 	"github.com/anacrolix/missinggo/perf"
 	"github.com/anacrolix/missinggo/pubsub"
+	"github.com/bradfitz/iter"
 
 	"github.com/anacrolix/torrent/bencode"
 	"github.com/anacrolix/torrent/metainfo"
@@ -1050,3 +1051,9 @@ func (t *torrent) readAt(b []byte, off int64) (n int, err error) {
 	}
 	return t.data.ReadAt(b, off)
 }
+
+func (t *torrent) updateAllPieceCompletions() {
+	for i := range iter.N(t.numPieces()) {
+		t.updatePieceCompletion(i)
+	}
+}