From 2cbfb91b88776ac3214cbac309c45a2b5370f987 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Tue, 3 Jun 2025 15:24:52 +0300 Subject: [PATCH] Use modern API to export torrent PR #22786. --- src/base/bittorrent/torrentimpl.cpp | 19 +++++-------------- src/base/bittorrent/torrentimpl.h | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 5ab957b58..87435816d 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -37,10 +37,10 @@ #endif #include -#include #include #include #include +#include #ifdef QBT_USES_LIBTORRENT2 #include @@ -2088,7 +2088,7 @@ void TorrentImpl::handleTorrentFinished() m_hasFinishedStatus = true; if (isMoveInProgress() || (m_renameCount > 0)) - m_moveFinishedTriggers.enqueue([this]() { m_session->handleTorrentFinished(this); }); + m_moveFinishedTriggers.enqueue([this] { m_session->handleTorrentFinished(this); }); else m_session->handleTorrentFinished(this); } @@ -2753,18 +2753,9 @@ nonstd::expected TorrentImpl::exportTorrent() const try { -#ifdef QBT_USES_LIBTORRENT2 - const std::shared_ptr completeTorrentInfo = m_nativeHandle.torrent_file_with_hashes(); - const std::shared_ptr torrentInfo = (completeTorrentInfo ? completeTorrentInfo : info().nativeInfo()); -#else - const std::shared_ptr torrentInfo = info().nativeInfo(); -#endif - lt::create_torrent creator {*torrentInfo}; - - for (const TrackerEntryStatus &status : asConst(trackers())) - creator.add_tracker(status.url.toStdString(), status.tier); - - return creator.generate(); + [[maybe_unused]] const auto infoGuard = qScopeGuard([this] { m_ltAddTorrentParams.ti.reset(); }); + m_ltAddTorrentParams.ti = info().nativeInfo(); + return lt::write_torrent_file(m_ltAddTorrentParams); } catch (const lt::system_error &err) { diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index b09568a7c..7b7064fd0 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -373,7 +373,7 @@ namespace BitTorrent bool m_unchecked = false; - lt::add_torrent_params m_ltAddTorrentParams; + mutable lt::add_torrent_params m_ltAddTorrentParams; int m_downloadLimit = 0; int m_uploadLimit = 0;