From 89b67d3871441955ef3a379dd340b8b940cd3551 Mon Sep 17 00:00:00 2001 From: AllSeeingEyeTolledEweSew Date: Tue, 22 Sep 2020 06:59:57 +0000 Subject: [PATCH] post save_resume_data_failed_alert if torrent was removed. Closes #5174 --- src/torrent.cpp | 7 +++++++ test/test_resume.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/torrent.cpp b/src/torrent.cpp index 4e3e84f46f6..4ef76fa39d6 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8574,6 +8574,13 @@ bool is_downloading_state(int const st) TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; + if (m_abort) + { + alerts().emplace_alert(get_handle() + , errors::torrent_removed); + return; + } + if ((flags & torrent_handle::only_if_modified) && !m_need_save_resume_data) { alerts().emplace_alert(get_handle() diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 8efb9a3124c..15ea612fc9c 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -1729,3 +1729,30 @@ TORRENT_TEST(resume_data_have_pieces) TEST_EQUAL(rs->params.unfinished_pieces.size(), 1); } +// See https://github.com/arvidn/libtorrent/issues/5174 +TORRENT_TEST(removed) +{ + lt::session ses(settings()); + std::shared_ptr ti = generate_torrent(); + add_torrent_params p; + p.ti = ti; + p.save_path = "."; + // we're _likely_ to trigger the condition, but not guaranteed. loop + // until we do. + bool triggered = false; + for (int i = 0; i < 10; i++) { + torrent_handle h = ses.add_torrent(p); + // this is asynchronous + ses.remove_torrent(h); + try { + h.save_resume_data(); + triggered = true; + } catch (std::exception const&) { + std::printf("failed to trigger condition, retrying\n"); + } + } + TEST_CHECK(triggered); + if (!triggered) return; + alert const* a = wait_for_alert(ses, save_resume_data_failed_alert::alert_type); + TEST_CHECK(a != nullptr); +}