@@ -1998,84 +1998,83 @@ namespace libtorrent
1998
1998
if (m_seed_mode)
1999
1999
{
2000
2000
m_have_all = true;
2001
- m_ses.get_io_service().post(boost::bind(&torrent::files_checked, shared_from_this()));
2002
- m_resume_data.reset();
2003
2001
update_gauge();
2004
2002
update_state_list();
2005
- return;
2006
2003
}
2007
-
2008
- set_state(torrent_status::checking_resume_data);
2009
-
2010
- int num_pad_files = 0;
2011
- TORRENT_ASSERT(block_size() > 0);
2012
- file_storage const& fs = m_torrent_file->files();
2013
- for (int i = 0; i < fs.num_files(); ++i)
2004
+ else
2014
2005
{
2015
- if (!fs.pad_file_at(i) || fs.file_size(i) == 0) continue;
2006
+ int num_pad_files = 0;
2007
+ TORRENT_ASSERT(block_size() > 0);
2008
+ file_storage const& fs = m_torrent_file->files();
2009
+ for (int i = 0; i < fs.num_files(); ++i)
2010
+ {
2011
+ if (!fs.pad_file_at(i) || fs.file_size(i) == 0) continue;
2016
2012
2017
- if (fs.pad_file_at(i)) ++num_pad_files;
2013
+ if (fs.pad_file_at(i)) ++num_pad_files;
2018
2014
2019
- m_padding += boost::uint32_t(fs.file_size(i));
2015
+ m_padding += boost::uint32_t(fs.file_size(i));
2020
2016
2021
- // TODO: instead of creating the picker up front here,
2022
- // maybe this whole section should move to need_picker()
2023
- need_picker();
2017
+ // TODO: instead of creating the picker up front here,
2018
+ // maybe this whole section should move to need_picker()
2019
+ need_picker();
2024
2020
2025
- peer_request pr = m_torrent_file->map_file(i, 0, fs.file_size(i));
2026
- int off = pr.start & (block_size()-1);
2027
- if (off != 0) { pr.length -= block_size() - off; pr.start += block_size() - off; }
2028
- TORRENT_ASSERT((pr.start & (block_size()-1)) == 0);
2021
+ peer_request pr = m_torrent_file->map_file(i, 0, fs.file_size(i));
2022
+ int off = pr.start & (block_size()-1);
2023
+ if (off != 0) { pr.length -= block_size() - off; pr.start += block_size() - off; }
2024
+ TORRENT_ASSERT((pr.start & (block_size()-1)) == 0);
2029
2025
2030
- int block = block_size();
2031
- int blocks_per_piece = m_torrent_file->piece_length() / block;
2032
- piece_block pb(pr.piece, pr.start / block);
2033
- for (; pr.length >= block; pr.length -= block, ++pb.block_index)
2034
- {
2035
- if (int(pb.block_index) == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
2036
- m_picker->mark_as_finished(pb, 0);
2026
+ int block = block_size();
2027
+ int blocks_per_piece = m_torrent_file->piece_length() / block;
2028
+ piece_block pb(pr.piece, pr.start / block);
2029
+ for (; pr.length >= block; pr.length -= block, ++pb.block_index)
2030
+ {
2031
+ if (int(pb.block_index) == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
2032
+ m_picker->mark_as_finished(pb, 0);
2033
+ }
2034
+ // ugly edge case where padfiles are not used they way they're
2035
+ // supposed to be. i.e. added back-to back or at the end
2036
+ if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
2037
+ if (pr.length > 0 && ((i+1 != fs.num_files() && fs.pad_file_at(i+1))
2038
+ || i + 1 == fs.num_files()))
2039
+ {
2040
+ m_picker->mark_as_finished(pb, 0);
2041
+ }
2037
2042
}
2038
- // ugly edge case where padfiles are not used they way they're
2039
- // supposed to be. i.e. added back-to back or at the end
2040
- if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
2041
- if (pr.length > 0 && ((i+1 != fs.num_files() && fs.pad_file_at(i+1))
2042
- || i + 1 == fs.num_files()))
2043
+
2044
+ if (m_padding > 0)
2043
2045
{
2044
- m_picker->mark_as_finished(pb, 0);
2045
- }
2046
- }
2046
+ // if we marked an entire piece as finished, we actually
2047
+ // need to consider it finished
2047
2048
2048
- if (m_padding > 0)
2049
- {
2050
- // if we marked an entire piece as finished, we actually
2051
- // need to consider it finished
2049
+ std::vector<piece_picker::downloading_piece> dq
2050
+ = m_picker->get_download_queue();
2052
2051
2053
- std::vector<piece_picker::downloading_piece> dq
2054
- = m_picker->get_download_queue();
2052
+ std::vector<int> have_pieces;
2055
2053
2056
- std::vector<int> have_pieces;
2054
+ for (std::vector<piece_picker::downloading_piece>::const_iterator i
2055
+ = dq.begin(); i != dq.end(); ++i)
2056
+ {
2057
+ int num_blocks = m_picker->blocks_in_piece(i->index);
2058
+ if (i->finished < num_blocks) continue;
2059
+ have_pieces.push_back(i->index);
2060
+ }
2057
2061
2058
- for (std::vector<piece_picker::downloading_piece>::const_iterator i
2059
- = dq.begin(); i != dq.end(); ++i)
2060
- {
2061
- int num_blocks = m_picker->blocks_in_piece(i->index);
2062
- if (i->finished < num_blocks) continue;
2063
- have_pieces.push_back(i->index);
2062
+ for (std::vector<int>::iterator i = have_pieces.begin();
2063
+ i != have_pieces.end(); ++i)
2064
+ {
2065
+ picker().piece_passed(*i);
2066
+ TORRENT_ASSERT(picker().have_piece(*i));
2067
+ we_have(*i);
2068
+ }
2064
2069
}
2065
2070
2066
- for (std::vector<int>::iterator i = have_pieces.begin();
2067
- i != have_pieces.end(); ++i)
2068
- {
2069
- picker().piece_passed(*i);
2070
- TORRENT_ASSERT(picker().have_piece(*i));
2071
- we_have(*i);
2072
- }
2073
- }
2071
+ if (!need_loaded()) return;
2074
2072
2075
- if (!need_loaded()) return;
2073
+ if (num_pad_files > 0)
2074
+ m_picker->set_num_pad_files(num_pad_files);
2075
+ }
2076
2076
2077
- if (num_pad_files > 0)
2078
- m_picker->set_num_pad_files(num_pad_files);
2077
+ set_state(torrent_status::checking_resume_data);
2079
2078
2080
2079
std::vector<std::string> links;
2081
2080
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
@@ -2350,7 +2349,7 @@ namespace libtorrent
2350
2349
// want anything in this function to affect the state of
2351
2350
// m_need_save_resume_data, so we save it in a local variable and reset
2352
2351
// it at the end of the function.
2353
- bool need_save_resume_data = m_need_save_resume_data;
2352
+ bool const need_save_resume_data = m_need_save_resume_data;
2354
2353
2355
2354
dec_refcount("check_fastresume");
2356
2355
TORRENT_ASSERT(is_single_thread());
@@ -2497,7 +2496,14 @@ namespace libtorrent
2497
2496
// that when the resume data check fails. For instance, if the resume data
2498
2497
// is incorrect, but we don't have any files, we skip the check and initialize
2499
2498
// the storage to not have anything.
2500
- if (j->ret == 0)
2499
+ if (m_seed_mode)
2500
+ {
2501
+ m_have_all = true;
2502
+ files_checked();
2503
+ update_gauge();
2504
+ update_state_list();
2505
+ }
2506
+ else if (j->ret == 0)
2501
2507
{
2502
2508
// there are either no files for this torrent
2503
2509
// or the resume_data was accepted
0 commit comments