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

@ -6724,7 +6724,7 @@ namespace libtorrent
// must be ordered in increasing order
static const country_entry country_map[] =
{
{ 4, "AF"}, { 8, "AL"}, { 10, "AQ"}, { 12, "DZ"}, { 16, "AS"}
{ 4, "AF"}, { 8, "AL"}, { 10, "AQ"}, { 12, "DZ"}, { 16, "AS"}
, { 20, "AD"}, { 24, "AO"}, { 28, "AG"}, { 31, "AZ"}, { 32, "AR"}
, { 36, "AU"}, { 40, "AT"}, { 44, "BS"}, { 48, "BH"}, { 50, "BD"}
, { 51, "AM"}, { 52, "BB"}, { 56, "BE"}, { 60, "BM"}, { 64, "BT"}
@ -7261,24 +7261,42 @@ namespace libtorrent
// for the piece
// bit 0: set if we have the piece
// bit 1: set if we have verified the piece (in seed mode)
entry::string_type& pieces = ret["pieces"].string();
pieces.resize(m_torrent_file->num_pieces());
if (!has_picker())
{
std::memset(&pieces[0], m_have_all, pieces.size());
}
else if (has_picker())
{
for (int i = 0, end(pieces.size()); i < end; ++i)
pieces[i] = m_picker->have_piece(i) ? 1 : 0;
}
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 (m_seed_mode)
// 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)
{
TORRENT_ASSERT(m_verified.size() == pieces.size());
TORRENT_ASSERT(m_verifying.size() == pieces.size());
for (int i = 0, end(pieces.size()); i < end; ++i)
pieces[i] |= m_verified[i] ? 2 : 0;
entry::string_type& pieces = ret["pieces"].string();
pieces.resize(max_piece);
if (!has_picker())
{
std::memset(&pieces[0], m_have_all, pieces.size());
}
else if (has_picker())
{
for (int i = 0, end(pieces.size()); i < end; ++i)
pieces[i] = m_picker->have_piece(i) ? 1 : 0;
}
if (m_seed_mode)
{
TORRENT_ASSERT(m_verified.size() == pieces.size());
TORRENT_ASSERT(m_verifying.size() == pieces.size());
for (int i = 0, end(pieces.size()); i < end; ++i)
pieces[i] |= m_verified[i] ? 2 : 0;
}
}
// write renamed files