Skip to content

Commit

Permalink
Improve received metadata handling
Browse files Browse the repository at this point in the history
Avoid blocking call to libtorrent when accessing underlying torrent_info object.

PR #20424.
  • Loading branch information
glassez committed Feb 21, 2024
1 parent bb8a012 commit 7786e1b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,12 @@ void TorrentImpl::deferredRequestResumeData()
{
if (!m_deferredRequestResumeDataInvoked)
{
QMetaObject::invokeMethod(this, [this] { requestResumeData(); }, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, [this]
{
requestResumeData((m_maintenanceJob == MaintenanceJob::HandleMetadata)
? lt::torrent_handle::save_info_dict : lt::resume_data_flags_t());
}, Qt::QueuedConnection);

m_deferredRequestResumeDataInvoked = true;
}
}
Expand Down Expand Up @@ -1706,8 +1711,8 @@ void TorrentImpl::resetTrackerEntries()

std::shared_ptr<const libtorrent::torrent_info> TorrentImpl::nativeTorrentInfo() const
{
if (m_nativeStatus.torrent_file.expired())
m_nativeStatus.torrent_file = m_nativeHandle.torrent_file();
Q_ASSERT(!m_nativeStatus.torrent_file.expired());

return m_nativeStatus.torrent_file.lock();
}

Expand Down Expand Up @@ -2041,7 +2046,7 @@ void TorrentImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p)
fetchURLSeeds([this](const QVector<QUrl> &urlSeeds) { m_urlSeeds = urlSeeds; });
}

if (m_maintenanceJob == MaintenanceJob::HandleMetadata)
if ((m_maintenanceJob == MaintenanceJob::HandleMetadata) && p->params.ti)
{
Q_ASSERT(m_indexMap.isEmpty());

Expand All @@ -2053,16 +2058,17 @@ void TorrentImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p)
m_ltAddTorrentParams.have_pieces.clear();
m_ltAddTorrentParams.verified_pieces.clear();

TorrentInfo metadata = TorrentInfo(*nativeTorrentInfo());
m_nativeStatus.torrent_file = m_ltAddTorrentParams.ti;

const auto metadata = TorrentInfo(*m_ltAddTorrentParams.ti);

const auto &renamedFiles = m_ltAddTorrentParams.renamed_files;
PathList filePaths = metadata.filePaths();
if (renamedFiles.empty() && (m_contentLayout != TorrentContentLayout::Original))
{
const Path originalRootFolder = Path::findRootFolder(filePaths);
const auto originalContentLayout = (originalRootFolder.isEmpty()
? TorrentContentLayout::NoSubfolder
: TorrentContentLayout::Subfolder);
? TorrentContentLayout::NoSubfolder : TorrentContentLayout::Subfolder);
if (m_contentLayout != originalContentLayout)
{
if (m_contentLayout == TorrentContentLayout::NoSubfolder)
Expand Down

0 comments on commit 7786e1b

Please sign in to comment.