Small tweaks
This commit is contained in:
parent
cd33f99352
commit
f466facd1a
2 changed files with 6 additions and 16 deletions
|
|
@ -205,13 +205,13 @@ impl ChunkTracker {
|
||||||
pub(crate) fn iter_queued_pieces<'a>(
|
pub(crate) fn iter_queued_pieces<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
file_priorities: &'a FilePriorities,
|
file_priorities: &'a FilePriorities,
|
||||||
opened_files: &'a FileInfos,
|
file_infos: &'a FileInfos,
|
||||||
) -> impl Iterator<Item = ValidPieceIndex> + 'a {
|
) -> impl Iterator<Item = ValidPieceIndex> + 'a {
|
||||||
file_priorities
|
file_priorities
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|p| opened_files.get(*p))
|
.filter_map(|p| Some((*p, file_infos.get(*p)?)))
|
||||||
// .filter(|f| !f.approx_is_finished())
|
.filter(|(id, f)| self.per_file_bytes[*id] != f.len)
|
||||||
.flat_map(|f| f.iter_piece_priorities())
|
.flat_map(|(_id, f)| f.iter_piece_priorities())
|
||||||
.filter(|id| self.queue_pieces[*id])
|
.filter(|id| self.queue_pieces[*id])
|
||||||
.filter_map(|id| id.try_into().ok())
|
.filter_map(|id| id.try_into().ok())
|
||||||
.filter_map(|id| self.lengths.validate_piece_index(id))
|
.filter_map(|id| self.lengths.validate_piece_index(id))
|
||||||
|
|
@ -249,12 +249,7 @@ impl ChunkTracker {
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.mark_piece_broken(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mark_piece_broken(&mut self, index: ValidPieceIndex) {
|
|
||||||
debug!("marking piece={} as broken", index);
|
debug!("marking piece={} as broken", index);
|
||||||
self.have.set(index.get() as usize, false);
|
|
||||||
self.queue_pieces.set(index.get() as usize, true);
|
self.queue_pieces.set(index.get() as usize, true);
|
||||||
if let Some(s) = self.chunk_status.get_mut(self.lengths.chunk_range(index)) {
|
if let Some(s) = self.chunk_status.get_mut(self.lengths.chunk_range(index)) {
|
||||||
s.fill(false);
|
s.fill(false);
|
||||||
|
|
|
||||||
|
|
@ -247,12 +247,6 @@ impl AsyncRead for FileStream {
|
||||||
|
|
||||||
self.as_mut().advance(bytes_to_read as u64);
|
self.as_mut().advance(bytes_to_read as u64);
|
||||||
tbuf.advance(bytes_to_read);
|
tbuf.advance(bytes_to_read);
|
||||||
self.streams
|
|
||||||
.streams
|
|
||||||
.get_mut(&self.stream_id)
|
|
||||||
.unwrap()
|
|
||||||
.value_mut()
|
|
||||||
.position = self.position;
|
|
||||||
|
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +299,7 @@ impl ManagedTorrent {
|
||||||
let files = match s {
|
let files = match s {
|
||||||
crate::ManagedTorrentState::Paused(p) => &*p.files,
|
crate::ManagedTorrentState::Paused(p) => &*p.files,
|
||||||
crate::ManagedTorrentState::Live(l) => &*l.files,
|
crate::ManagedTorrentState::Live(l) => &*l.files,
|
||||||
_ => anyhow::bail!("invalid state"),
|
s => anyhow::bail!("with_storage_and_file: invalid state: {}", s.name()),
|
||||||
};
|
};
|
||||||
let fi = self
|
let fi = self
|
||||||
.info()
|
.info()
|
||||||
|
|
@ -338,6 +332,7 @@ impl ManagedTorrent {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_file_finished(&self, file_id: usize) -> bool {
|
fn is_file_finished(&self, file_id: usize) -> bool {
|
||||||
|
// TODO: would be nice to remove locking
|
||||||
self.with_chunk_tracker(|ct| ct.is_file_finished(&self.info.file_infos[file_id]))
|
self.with_chunk_tracker(|ct| ct.is_file_finished(&self.info.file_infos[file_id]))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue