Refresh all piece completion states when data is missing

This commit is contained in:
Matt Joiner 2016-02-21 17:24:59 +11:00
parent 99e9f41a33
commit 5b443fb63d
2 changed files with 9 additions and 2 deletions

View File

@ -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()
}
}

View 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)
}
}