only save pieces in resume data that have actually been checked

This commit is contained in:
arvidn 2016-02-20 00:48:17 -05:00
parent a675a749e0
commit 5cf36fd1d6
1 changed files with 41 additions and 23 deletions

View File

@ -7261,8 +7261,25 @@ namespace libtorrent
// for the piece // for the piece
// bit 0: set if we have the piece // bit 0: set if we have the piece
// bit 1: set if we have verified the piece (in seed mode) // bit 1: set if we have verified the piece (in seed mode)
bool const is_checking = state() == torrent_status::checking_files;
bool const has_checked = state() == torrent_status::downloading
|| state() == torrent_status::finished
|| state() == torrent_status::seeding;
// if we are checking, only save the have_pieces bitfield up to the piece
// we have actually checked. This allows us to resume the checking when we
// load this torrent up again. If we have not completed checking nor is
// currently checking, don't save any pieces from the have_pieces
// bitfield.
int const max_piece
= is_checking ? m_num_checked_pieces
: has_checked ? m_torrent_file->num_pieces()
: 0;
if (max_piece > 0)
{
entry::string_type& pieces = ret["pieces"].string(); entry::string_type& pieces = ret["pieces"].string();
pieces.resize(m_torrent_file->num_pieces()); pieces.resize(max_piece);
if (!has_picker()) if (!has_picker())
{ {
std::memset(&pieces[0], m_have_all, pieces.size()); std::memset(&pieces[0], m_have_all, pieces.size());
@ -7280,6 +7297,7 @@ namespace libtorrent
for (int i = 0, end(pieces.size()); i < end; ++i) for (int i = 0, end(pieces.size()); i < end; ++i)
pieces[i] |= m_verified[i] ? 2 : 0; pieces[i] |= m_verified[i] ? 2 : 0;
} }
}
// write renamed files // write renamed files
// TODO: 0 make this more generic to not just work if files have been // TODO: 0 make this more generic to not just work if files have been