diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index a6975395f..0f159a00f 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1808,7 +1808,7 @@ TORRENT_VERSION_NAMESPACE_2 // internal cache_flushed_alert(aux::stack_allocator& alloc, torrent_handle const& h); - TORRENT_DEFINE_ALERT(cache_flushed_alert, 58) + TORRENT_DEFINE_ALERT_PRIO(cache_flushed_alert, 58, alert_priority_high) static constexpr alert_category_t static_category = alert::storage_notification; }; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 63afbdc79..abe61cb41 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1174,7 +1174,7 @@ namespace libtorrent { void on_file_renamed(std::string const& filename , file_index_t file_idx , storage_error const& error); - void on_cache_flushed(); + void on_cache_flushed(bool manually_triggered); // this is used when a torrent is being removed.It synchronizes with the // disk thread diff --git a/src/torrent.cpp b/src/torrent.cpp index f22d03b11..e48423fcf 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2242,7 +2242,7 @@ bool is_downloading_state(int const st) // this will clear the stat cache, to make us actually query the // filesystem for files again - m_ses.disk_thread().async_release_files(m_storage, []{}); + m_ses.disk_thread().async_release_files(m_storage); aux::vector links; m_ses.disk_thread().async_check_files(m_storage, nullptr @@ -7379,7 +7379,7 @@ bool is_downloading_state(int const st) { // we need to keep the object alive during this operation m_ses.disk_thread().async_release_files(m_storage - , std::bind(&torrent::on_cache_flushed, shared_from_this())); + , std::bind(&torrent::on_cache_flushed, shared_from_this(), false)); } // this torrent just completed downloads, which means it will fall @@ -8463,16 +8463,16 @@ bool is_downloading_state(int const st) return; } m_ses.disk_thread().async_release_files(m_storage - , std::bind(&torrent::on_cache_flushed, shared_from_this())); + , std::bind(&torrent::on_cache_flushed, shared_from_this(), true)); } - void torrent::on_cache_flushed() try + void torrent::on_cache_flushed(bool const manually_triggered) try { TORRENT_ASSERT(is_single_thread()); if (m_ses.is_aborted()) return; - if (alerts().should_post()) + if (manually_triggered || alerts().should_post()) alerts().emplace_alert(get_handle()); } catch (...) { handle_exception(); } diff --git a/test/test_alert_types.cpp b/test/test_alert_types.cpp index 54c583679..782517784 100644 --- a/test/test_alert_types.cpp +++ b/test/test_alert_types.cpp @@ -127,7 +127,7 @@ TORRENT_TEST(alerts_types) TEST_ALERT_TYPE(dht_announce_alert, 55, 0, alert::dht_notification); TEST_ALERT_TYPE(dht_get_peers_alert, 56, 0, alert::dht_notification); TEST_ALERT_TYPE(stats_alert, 57, 0, alert::stats_notification); - TEST_ALERT_TYPE(cache_flushed_alert, 58, 0, alert::storage_notification); + TEST_ALERT_TYPE(cache_flushed_alert, 58, 1, alert::storage_notification); #if TORRENT_ABI_VERSION == 1 TEST_ALERT_TYPE(anonymous_mode_alert, 59, 0, alert::error_notification); #else