Skip to content

Commit

Permalink
Add piece flush location suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Jun 22, 2022
1 parent 276373b commit 2c56fa7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2008,12 +2008,14 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
}
t.clearPieceTouchers(piece)
t.cl.unlock()
if p.hasDirtyChunks() {
p.Storage().Flush() // You can be synchronous here!
}
err := p.Storage().MarkComplete()
if err != nil {
t.logger.Printf("%T: error marking piece complete %d: %s", t.storage, piece, err)
}
t.cl.lock()

if t.closed.IsSet() {
return
}
Expand Down Expand Up @@ -2088,7 +2090,6 @@ func (t *Torrent) onPieceCompleted(piece pieceIndex) {
conn.have(piece)
t.maybeDropMutuallyCompletePeer(&conn.Peer)
}
t.piece(piece).Storage().MarkComplete()
}

// Called when a piece is found to be not complete.
Expand Down

0 comments on commit 2c56fa7

Please sign in to comment.