]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Refresh all piece completion states when data is missing
authorMatt Joiner <anacrolix@gmail.com>
Sun, 21 Feb 2016 06:24:59 +0000 (17:24 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 21 Feb 2016 06:24:59 +0000 (17:24 +1100)
reader.go
torrent.go

index 0f92343a20c3b448d8567b8e37a2071836f030a7..f0b81668d4279c69a74fe43dfeec527b16637954 100644 (file)
--- 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()
        }
 }
index daca65c0a3871fe2fc4a3e1146150a2c6e8a86dc..3bbbcef8623bb73417fdc83b0dde7ad650403a8f 100644 (file)
@@ -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)
+       }
+}