@@ -573,7 +573,7 @@ namespace libtorrent {
573
573
m_seed_mode = false ;
574
574
// seed is false if we turned out not
575
575
// to be a seed after all
576
- if (!skip_checking)
576
+ if (!skip_checking && state () != torrent_status::checking_resume_data )
577
577
{
578
578
m_have_all = false ;
579
579
set_state (torrent_status::downloading);
@@ -1787,80 +1787,78 @@ namespace libtorrent {
1787
1787
if (m_seed_mode)
1788
1788
{
1789
1789
m_have_all = true ;
1790
- auto self = shared_from_this ();
1791
- m_ses.get_io_service ().post ([self] { self->wrap (&torrent::files_checked); });
1792
- TORRENT_ASSERT (m_outstanding_check_files == false );
1793
- m_add_torrent_params.reset ();
1794
1790
update_gauge ();
1795
1791
update_state_list ();
1796
- return ;
1797
1792
}
1798
-
1799
- set_state (torrent_status::checking_resume_data);
1800
-
1801
- int num_pad_files = 0 ;
1802
- TORRENT_ASSERT (block_size () > 0 );
1803
- for (file_index_t i (0 ); i < fs.end_file (); ++i)
1793
+ else
1804
1794
{
1805
- if (fs.pad_file_at (i)) ++num_pad_files;
1795
+ int num_pad_files = 0 ;
1796
+ TORRENT_ASSERT (block_size () > 0 );
1806
1797
1807
- if (!fs.pad_file_at (i) || fs.file_size (i) == 0 ) continue ;
1808
- m_padding += std::uint32_t (fs.file_size (i));
1798
+ for (file_index_t i (0 ); i < fs.end_file (); ++i)
1799
+ {
1800
+ if (fs.pad_file_at (i)) ++num_pad_files;
1809
1801
1810
- // TODO: instead of creating the picker up front here,
1811
- // maybe this whole section should move to need_picker()
1812
- need_picker ();
1802
+ if (!fs.pad_file_at (i) || fs.file_size (i) == 0 ) continue ;
1803
+ m_padding += std::uint32_t (fs.file_size (i));
1813
1804
1814
- peer_request pr = m_torrent_file->map_file (i, 0 , int (fs.file_size (i)));
1815
- int off = pr.start & (block_size () - 1 );
1816
- if (off != 0 ) { pr.length -= block_size () - off; pr.start += block_size () - off; }
1817
- TORRENT_ASSERT ((pr.start & (block_size () - 1 )) == 0 );
1805
+ // TODO: instead of creating the picker up front here,
1806
+ // maybe this whole section should move to need_picker()
1807
+ need_picker ();
1818
1808
1819
- int block = block_size ();
1820
- int blocks_per_piece = m_torrent_file->piece_length () / block;
1821
- piece_block pb (pr.piece , pr.start / block);
1822
- for (; pr.length >= block; pr.length -= block, ++pb.block_index )
1823
- {
1809
+ peer_request pr = m_torrent_file->map_file (i, 0 , int (fs.file_size (i)));
1810
+ int off = pr.start & (block_size () - 1 );
1811
+ if (off != 0 ) { pr.length -= block_size () - off; pr.start += block_size () - off; }
1812
+ TORRENT_ASSERT ((pr.start & (block_size () - 1 )) == 0 );
1813
+
1814
+ int block = block_size ();
1815
+ int blocks_per_piece = m_torrent_file->piece_length () / block;
1816
+ piece_block pb (pr.piece , pr.start / block);
1817
+ for (; pr.length >= block; pr.length -= block, ++pb.block_index )
1818
+ {
1819
+ if (pb.block_index == blocks_per_piece) { pb.block_index = 0 ; ++pb.piece_index ; }
1820
+ m_picker->mark_as_finished (pb, nullptr );
1821
+ }
1822
+ // ugly edge case where padfiles are not used they way they're
1823
+ // supposed to be. i.e. added back-to back or at the end
1824
1824
if (pb.block_index == blocks_per_piece) { pb.block_index = 0 ; ++pb.piece_index ; }
1825
- m_picker->mark_as_finished (pb, nullptr );
1825
+ if (pr.length > 0 && ((next (i) != fs.end_file () && fs.pad_file_at (next (i)))
1826
+ || next (i) == fs.end_file ()))
1827
+ {
1828
+ m_picker->mark_as_finished (pb, nullptr );
1829
+ }
1826
1830
}
1827
- // ugly edge case where padfiles are not used they way they're
1828
- // supposed to be. i.e. added back-to back or at the end
1829
- if (pb.block_index == blocks_per_piece) { pb.block_index = 0 ; ++pb.piece_index ; }
1830
- if (pr.length > 0 && ((next (i) != fs.end_file () && fs.pad_file_at (next (i)))
1831
- || next (i) == fs.end_file ()))
1831
+
1832
+ if (m_padding > 0 )
1832
1833
{
1833
- m_picker->mark_as_finished (pb, nullptr );
1834
- }
1835
- }
1834
+ // if we marked an entire piece as finished, we actually
1835
+ // need to consider it finished
1836
1836
1837
- if (m_padding > 0 )
1838
- {
1839
- // if we marked an entire piece as finished, we actually
1840
- // need to consider it finished
1837
+ std::vector<piece_picker::downloading_piece> dq
1838
+ = m_picker->get_download_queue ();
1841
1839
1842
- std::vector<piece_picker::downloading_piece> dq
1843
- = m_picker->get_download_queue ();
1840
+ std::vector<piece_index_t > have_pieces;
1844
1841
1845
- std::vector<piece_index_t > have_pieces;
1842
+ for (auto const & p : dq)
1843
+ {
1844
+ int const num_blocks = m_picker->blocks_in_piece (p.index );
1845
+ if (p.finished < num_blocks) continue ;
1846
+ have_pieces.push_back (p.index );
1847
+ }
1846
1848
1847
- for (auto const & p : dq)
1848
- {
1849
- int const num_blocks = m_picker->blocks_in_piece (p.index );
1850
- if (p.finished < num_blocks) continue ;
1851
- have_pieces.push_back (p.index );
1849
+ for (auto i : have_pieces)
1850
+ {
1851
+ picker ().piece_passed (i);
1852
+ TORRENT_ASSERT (picker ().have_piece (i));
1853
+ we_have (i);
1854
+ }
1852
1855
}
1853
1856
1854
- for (auto i : have_pieces)
1855
- {
1856
- picker ().piece_passed (i);
1857
- TORRENT_ASSERT (picker ().have_piece (i));
1858
- we_have (i);
1859
- }
1857
+ if (num_pad_files > 0 )
1858
+ m_picker->set_num_pad_files (num_pad_files);
1860
1859
}
1861
1860
1862
- if (num_pad_files > 0 )
1863
- m_picker->set_num_pad_files (num_pad_files);
1861
+ set_state (torrent_status::checking_resume_data);
1864
1862
1865
1863
aux::vector<std::string, file_index_t > links;
1866
1864
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
@@ -2074,7 +2072,13 @@ namespace libtorrent {
2074
2072
// that when the resume data check fails. For instance, if the resume data
2075
2073
// is incorrect, but we don't have any files, we skip the check and initialize
2076
2074
// the storage to not have anything.
2077
- if (status == status_t ::no_error)
2075
+ if (m_seed_mode)
2076
+ {
2077
+ m_have_all = true ;
2078
+ update_gauge ();
2079
+ update_state_list ();
2080
+ }
2081
+ else if (status == status_t ::no_error)
2078
2082
{
2079
2083
// there are either no files for this torrent
2080
2084
// or the resume_data was accepted
@@ -5244,7 +5248,7 @@ namespace libtorrent {
5244
5248
k = m_trackers.insert (k, url);
5245
5249
k->endpoints .clear ();
5246
5250
if (k->source == 0 ) k->source = announce_entry::source_client;
5247
- if (!m_paused && !m_trackers.empty ()) announce_with_tracker ();
5251
+ if (m_announcing && !m_trackers.empty ()) announce_with_tracker ();
5248
5252
return true ;
5249
5253
}
5250
5254
0 commit comments