From b8614a36b38f8bd4084d2e3004020ec503bb5f4a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 5 Jun 2011 20:48:00 +0000 Subject: [PATCH] fix resume state for paused when torrent was in graceful pause mode --- examples/client_test.cpp | 11 ++++++++--- include/libtorrent/torrent.hpp | 6 ++++++ src/session_impl.cpp | 1 + src/torrent.cpp | 23 ++++++++++++++++++++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index c22f4be5f..4cc51c866 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -862,6 +862,14 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a , boost::bind(&handles_t::value_type::second, _1) == h) == files.end()) ses.remove_torrent(h); } + else if (torrent_paused_alert* p = alert_cast(a)) + { + // write resume data for the finished torrent + // the alert handler for save_resume_data_alert + // will save it to disk + torrent_handle h = p->handle; + h.save_resume_data(); + } } static char const* state_str[] = @@ -1486,9 +1494,6 @@ int main(int argc, char* argv[]) ts.handle.auto_managed(false); ts.handle.pause(torrent_handle::graceful_pause); } - // the alert handler for save_resume_data_alert - // will save it to disk - if (ts.need_save_resume) ts.handle.save_resume_data(); } if (c == 'c' && !handles.empty()) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index adec46163..5e0c326df 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1318,6 +1318,12 @@ namespace libtorrent // if set to true, add tracker URLs loaded from resume // data into this torrent instead of replacing them bool m_merge_resume_trackers:1; + +#ifdef TORRENT_DEBUG + public: + // set to false until we've loaded resume data + bool m_resume_data_loaded; +#endif }; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 6c64246a2..ba3dd13a4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3507,6 +3507,7 @@ namespace aux { if (t->state() == torrent_status::checking_files || t->state() == torrent_status::queued_for_checking) continue; + TORRENT_ASSERT(t->m_resume_data_loaded); if (t->is_auto_managed() && !t->has_error()) { // this torrent is auto managed, add it to diff --git a/src/torrent.cpp b/src/torrent.cpp index 70ace44a2..2b20d963d 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -409,6 +409,9 @@ namespace libtorrent , m_apply_ip_filter(p.apply_ip_filter) , m_merge_resume_trackers(p.merge_resume_trackers) { +#ifdef TORRENT_DEBUG + m_resume_data_loaded = false; +#endif if (!m_apply_ip_filter) ++m_ses.m_non_filtered_torrents; if (!p.ti || !p.ti->is_valid()) @@ -1352,6 +1355,10 @@ namespace libtorrent } } +#ifdef TORRENT_DEBUG + m_resume_data_loaded = true; +#endif + TORRENT_ASSERT(block_size() > 0); int file = 0; for (file_storage::iterator i = m_torrent_file->files().begin() @@ -3415,6 +3422,9 @@ namespace libtorrent } if (filter_updated) { + // we need to save this new state + m_need_save_resume_data = true; + update_peer_interest(was_finished); remove_time_critical_pieces(pieces); } @@ -4789,7 +4799,7 @@ namespace libtorrent ret["download_rate_limit"] = download_limit(); ret["max_connections"] = max_connections(); ret["max_uploads"] = max_uploads(); - ret["paused"] = !m_allow_peers; + ret["paused"] = is_torrent_paused(); ret["announce_to_dht"] = m_announce_to_dht; ret["announce_to_trackers"] = m_announce_to_trackers; ret["announce_to_lsd"] = m_announce_to_lsd; @@ -6055,6 +6065,10 @@ namespace libtorrent if (m_auto_managed == a) return; bool checking_files = should_check_files(); m_auto_managed = a; + + // we need to save this new state as well + m_need_save_resume_data = true; + // recalculate which torrents should be // paused m_ses.m_auto_manage_time_scaler = 0; @@ -6232,6 +6246,9 @@ namespace libtorrent m_announce_to_trackers = false; m_announce_to_lsd = false; + // we need to save this new state + m_need_save_resume_data = true; + bool prev_graceful = m_graceful_pause_mode; m_graceful_pause_mode = graceful; @@ -6382,6 +6399,10 @@ namespace libtorrent m_announce_to_trackers = true; m_announce_to_lsd = true; if (!m_ses.is_paused()) m_graceful_pause_mode = false; + + // we need to save this new state + m_need_save_resume_data = true; + do_resume(); }