From 0ba2e2cdbddc3049ab544d5970d38d425790c4ee Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 27 Jan 2009 09:18:51 +0000 Subject: [PATCH] fixed issue where torrents that failed checking would not resume checking when the error was cleared. One side effect of this fix is that it should now be possible to pause checking torrents with the 0.14 branch --- include/libtorrent/torrent.hpp | 5 ++--- src/session_impl.cpp | 8 ++------ src/torrent.cpp | 23 ++++++++++++++++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 3372a8d7d..1ec508320 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -218,8 +218,6 @@ namespace libtorrent torrent_status::state_t state() const { return m_state; } void set_state(torrent_status::state_t s); - void clear_error(); - session_settings const& settings() const; aux::session_impl& session() { return m_ses; } @@ -247,7 +245,8 @@ namespace libtorrent void ip_filter_updated() { m_policy.ip_filter_updated(); } - void set_error(std::string const& msg) { m_error = msg; } + void clear_error(); + void set_error(std::string const& msg); bool has_error() const { return !m_error.empty(); } void pause(); void resume(); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 89b11ceb9..e13e630e0 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1501,12 +1501,8 @@ namespace aux { { --hard_limit; ++total_running; - if (t->state() != torrent_status::queued_for_checking - && t->state() != torrent_status::checking_files) - { - --num_downloaders; - if (t->is_paused()) t->resume(); - } + --num_downloaders; + if (t->is_paused()) t->resume(); } else { diff --git a/src/torrent.cpp b/src/torrent.cpp index b92cd0ab9..bade1c155 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -580,7 +580,7 @@ namespace libtorrent if (m_torrent_file->num_pieces() > piece_picker::max_pieces) { - m_error = "too many pieces in torrent"; + set_error("too many pieces in torrent"); pause(); } @@ -682,7 +682,7 @@ namespace libtorrent " ]\n"; #endif } - m_error = j.str; + set_error(j.str); pause(); set_state(torrent_status::queued_for_checking); @@ -879,7 +879,7 @@ namespace libtorrent " ]\n"; #endif } - m_error = j.str; + set_error(j.str); pause(); return; } @@ -923,7 +923,7 @@ namespace libtorrent #endif } pause(); - m_error = j.str; + set_error(j.str); if (!m_abort) m_ses.done_checking(shared_from_this()); set_state(torrent_status::queued_for_checking); return; @@ -4338,6 +4338,19 @@ namespace libtorrent m_ses.check_torrent(shared_from_this()); } + void torrent::set_error(std::string const& msg) + { + bool checking_files = should_check_files(); + m_error = msg; + if (checking_files && !should_check_files()) + { + // stop checking + m_storage->abort_disk_io(); + m_ses.done_checking(shared_from_this()); + set_state(torrent_status::queued_for_checking); + } + } + void torrent::auto_managed(bool a) { INVARIANT_CHECK; @@ -4846,7 +4859,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.str)); - m_error = j.str; + set_error(j.str); pause(); } f(ret);