Fix a bug when remarking already have pieces broken
This commit is contained in:
parent
0ff63d8a24
commit
b808382169
2 changed files with 14 additions and 10 deletions
|
|
@ -157,16 +157,20 @@ impl ChunkTracker {
|
||||||
Some(true)
|
Some(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_piece_broken(&mut self, index: ValidPieceIndex) -> bool {
|
pub fn mark_piece_broken_if_not_have(&mut self, index: ValidPieceIndex) {
|
||||||
|
if self
|
||||||
|
.have
|
||||||
|
.get(index.get() as usize)
|
||||||
|
.map(|r| *r)
|
||||||
|
.unwrap_or_default()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
debug!("remarking piece={} as broken", index);
|
debug!("remarking piece={} as broken", index);
|
||||||
self.needed_pieces.set(index.get() as usize, true);
|
self.needed_pieces.set(index.get() as usize, true);
|
||||||
self.chunk_status
|
if let Some(s) = self.chunk_status.get_mut(self.lengths.chunk_range(index)) {
|
||||||
.get_mut(self.lengths.chunk_range(index))
|
s.fill(false);
|
||||||
.map(|s| {
|
}
|
||||||
s.fill(false);
|
|
||||||
true
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_piece_downloaded(&mut self, idx: ValidPieceIndex) {
|
pub fn mark_piece_downloaded(&mut self, idx: ValidPieceIndex) {
|
||||||
|
|
|
||||||
|
|
@ -748,7 +748,7 @@ impl TorrentStateLive {
|
||||||
.take()
|
.take()
|
||||||
.context("bug: pausing already paused torrent")?;
|
.context("bug: pausing already paused torrent")?;
|
||||||
for piece_id in g.inflight_pieces.keys().copied() {
|
for piece_id in g.inflight_pieces.keys().copied() {
|
||||||
chunk_tracker.mark_piece_broken(piece_id);
|
chunk_tracker.mark_piece_broken_if_not_have(piece_id);
|
||||||
}
|
}
|
||||||
let have_bytes = chunk_tracker.calc_have_bytes();
|
let have_bytes = chunk_tracker.calc_have_bytes();
|
||||||
let needed_bytes = chunk_tracker.calc_needed_bytes();
|
let needed_bytes = chunk_tracker.calc_needed_bytes();
|
||||||
|
|
@ -1494,7 +1494,7 @@ impl PeerHandler {
|
||||||
self.state
|
self.state
|
||||||
.lock_write("mark_piece_broken")
|
.lock_write("mark_piece_broken")
|
||||||
.get_chunks_mut()?
|
.get_chunks_mut()?
|
||||||
.mark_piece_broken(chunk_info.piece_index);
|
.mark_piece_broken_if_not_have(chunk_info.piece_index);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok::<_, anyhow::Error>(())
|
Ok::<_, anyhow::Error>(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue