fix re-prioritizing a piece while it is downloading (#987)

update_piece_state does not expect that the piece's priority has also changed
since the last time the piece was updated. Make sure the piece's priority is
updated before trying to update the state.
This commit is contained in:
Steven Siloti 2016-08-07 12:27:04 -07:00 committed by Arvid Norberg
parent 61031f1186
commit d4296730d0
1 changed files with 12 additions and 11 deletions

View File

@ -1834,17 +1834,8 @@ namespace libtorrent
p.piece_priority = new_piece_priority; p.piece_priority = new_piece_priority;
int new_priority = p.priority(this); int new_priority = p.priority(this);
if (p.downloading()) if (prev_priority != new_priority && !m_dirty)
{ {
std::vector<downloading_piece>::iterator i = find_dl_piece(
p.download_queue(), index);
if (i != m_downloads[p.download_queue()].end())
update_piece_state(i);
}
if (prev_priority == new_priority) return ret;
if (m_dirty) return ret;
if (prev_priority == -1) if (prev_priority == -1)
{ {
add(index); add(index);
@ -1853,6 +1844,16 @@ namespace libtorrent
{ {
update(prev_priority, p.index); update(prev_priority, p.index);
} }
}
if (p.downloading())
{
std::vector<downloading_piece>::iterator i = find_dl_piece(
p.download_queue(), index);
if (i != m_downloads[p.download_queue()].end())
update_piece_state(i);
}
return ret; return ret;
} }