From 5af78ad2cd3d2d776b41f29b3a88f58b55919765 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Tue, 10 May 2022 15:34:38 +0300 Subject: [PATCH] Preserve "skip hash check" when there is no metadata When torrent is added without metadata libtorrent doesn't honor "seed mode" and doesn't save it in resume data so when metadata is available torrent will still check file hashes. This patch will add a logic that preserves originally enabled "seed mode" until the metadata is received. PR #17009. --- src/base/bittorrent/torrentimpl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 0e4abc142..c3463e6cd 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1793,7 +1793,10 @@ void TorrentImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) { Q_ASSERT(m_indexMap.isEmpty()); + const auto isSeedMode = static_cast(m_ltAddTorrentParams.flags & lt::torrent_flags::seed_mode); m_ltAddTorrentParams = p->params; + if (isSeedMode) + m_ltAddTorrentParams.flags |= lt::torrent_flags::seed_mode; m_ltAddTorrentParams.have_pieces.clear(); m_ltAddTorrentParams.verified_pieces.clear(); @@ -1852,8 +1855,11 @@ void TorrentImpl::prepareResumeData(const lt::add_torrent_params ¶ms) } else { + const bool preserveSeedMode = (!hasMetadata() && (m_ltAddTorrentParams.flags & lt::torrent_flags::seed_mode)); // Update recent resume data m_ltAddTorrentParams = params; + if (preserveSeedMode) + m_ltAddTorrentParams.flags |= lt::torrent_flags::seed_mode; } // We shouldn't save upload_mode flag to allow torrent operate normally on next run