From 54f00ce09dadae5d265c209a13d1e87322d68577 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Fri, 18 May 2018 09:57:36 -0700 Subject: [PATCH] don't change state to downloading if the torrent is finished Move the transition to downloading after the torrent has been checked for being finished. This prevents a spurious state_changed_alert when adding a torrent which is already completed. Also move the posting of the torrent_checked_alert to maintain the historical ordering of that alert with respect to the transition out of checking_resume_data. --- src/torrent.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index fee1f047b..99fcc5781 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8829,24 +8829,6 @@ namespace { return; } - // we might be finished already, in which case we should - // not switch to downloading mode. If all files are - // filtered, we're finished when we start. - if (m_state != torrent_status::finished - && m_state != torrent_status::seeding - && !m_seed_mode) - { - set_state(torrent_status::downloading); - } - - INVARIANT_CHECK; - - if (m_ses.alerts().should_post()) - { - m_ses.alerts().emplace_alert( - get_handle()); - } - // calling pause will also trigger the auto managed // recalculation // if we just got here by downloading the metadata, @@ -8883,6 +8865,24 @@ namespace { finished(); } + // we might be finished already, in which case we should + // not switch to downloading mode. If all files are + // filtered, we're finished when we start. + if (m_state != torrent_status::finished + && m_state != torrent_status::seeding + && !m_seed_mode) + { + set_state(torrent_status::downloading); + } + + INVARIANT_CHECK; + + if (m_ses.alerts().should_post()) + { + m_ses.alerts().emplace_alert( + get_handle()); + } + #ifndef TORRENT_DISABLE_EXTENSIONS for (extension_list_t::iterator i = m_extensions.begin() , end(m_extensions.end()); i != end; ++i)