From b822d2c380cb745f5f97a20d411caea0073bbd09 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 22 Jul 2019 14:22:26 +0300 Subject: [PATCH] Fix requested torrent resume data handling Session should increase an appropriate counter each time the torrent resume data is requested to save. --- src/base/bittorrent/session.cpp | 49 +++++++++++++-------------- src/base/bittorrent/session.h | 2 +- src/base/bittorrent/torrenthandle.cpp | 1 + 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 80f9814a9..ca6e696ef 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1796,6 +1796,12 @@ void Session::bottomTorrentsQueuePos(const QStringList &hashes) saveTorrentsQueue(); } +void Session::handleTorrentSaveResumeDataRequested(TorrentHandle *const torrent) +{ + qDebug("Saving resume data is requested for torrent '%s'...", qUtf8Printable(torrent->name())); + ++m_numResumeData; +} + QHash Session::torrents() const { return m_torrents; @@ -2166,7 +2172,7 @@ void Session::generateResumeData(const bool final) || torrent->hasMissingFiles()) continue; - saveTorrentResumeData(torrent); + torrent->saveResumeData(); } } @@ -3358,55 +3364,48 @@ void Session::updateSeedingLimitTimer() void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); - updateSeedingLimitTimer(); -} - -void Session::saveTorrentResumeData(TorrentHandle *const torrent) -{ - qDebug("Saving fastresume data for %s", qUtf8Printable(torrent->name())); torrent->saveResumeData(); - ++m_numResumeData; + updateSeedingLimitTimer(); } void Session::handleTorrentNameChanged(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); } void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentSavePathChanged(torrent); } void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentCategoryChanged(torrent, oldCategory); } void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentTagAdded(torrent, tag); } void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentTagRemoved(torrent, tag); } void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentSavingModeChanged(torrent); } void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector &newTrackers) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); for (const TrackerEntry &newTracker : newTrackers) LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name())); @@ -3418,7 +3417,7 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVe void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector &deletedTrackers) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); for (const TrackerEntry &deletedTracker : deletedTrackers) LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); @@ -3430,27 +3429,27 @@ void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const Q void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit trackersChanged(torrent); } void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList &newUrlSeeds) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); for (const QUrl &newUrlSeed : newUrlSeeds) LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name())); } void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList &urlSeeds) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); for (const QUrl &urlSeed : urlSeeds) LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name())); } void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); // Save metadata const QDir resumeDataDir(m_resumeFolderPath); @@ -3467,13 +3466,13 @@ void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent) void Session::handleTorrentPaused(TorrentHandle *const torrent) { if (!torrent->hasError() && !torrent->hasMissingFiles()) - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentPaused(torrent); } void Session::handleTorrentResumed(TorrentHandle *const torrent) { - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentResumed(torrent); } @@ -3485,7 +3484,7 @@ void Session::handleTorrentChecked(TorrentHandle *const torrent) void Session::handleTorrentFinished(TorrentHandle *const torrent) { if (!torrent->hasError() && !torrent->hasMissingFiles()) - saveTorrentResumeData(torrent); + torrent->saveResumeData(); emit torrentFinished(torrent); qDebug("Checking if the torrent contains torrent files to download"); @@ -3989,7 +3988,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) // In case of crash before the scheduled generation // of the fastresumes. - saveTorrentResumeData(torrent); + torrent->saveResumeData(); } if (((torrent->ratioLimit() >= 0) || (torrent->seedingTimeLimit() >= 0)) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index e99270037..a8eee8b71 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -427,6 +427,7 @@ namespace BitTorrent void bottomTorrentsQueuePos(const QStringList &hashes); // TorrentHandle interface + void handleTorrentSaveResumeDataRequested(TorrentHandle *const torrent); void handleTorrentShareLimitChanged(TorrentHandle *const torrent); void handleTorrentNameChanged(TorrentHandle *const torrent); void handleTorrentSavePathChanged(TorrentHandle *const torrent); @@ -544,7 +545,6 @@ namespace BitTorrent void updateSeedingLimitTimer(); void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular); - void saveTorrentResumeData(TorrentHandle *const torrent); void handleAlert(const lt::alert *a); void dispatchTorrentAlert(const lt::alert *a); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 006298cc5..e8db78a87 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -530,6 +530,7 @@ bool TorrentHandle::needSaveResumeData() const void TorrentHandle::saveResumeData() { m_nativeHandle.save_resume_data(); + m_session->handleTorrentSaveResumeDataRequested(this); } int TorrentHandle::filesCount() const