diff --git a/src/base/addtorrentmanager.cpp b/src/base/addtorrentmanager.cpp index bce47d6ab615..df343eb68536 100644 --- a/src/base/addtorrentmanager.cpp +++ b/src/base/addtorrentmanager.cpp @@ -158,7 +158,7 @@ void AddTorrentManager::handleAddTorrentFailed(const QString &source, const QStr emit addTorrentFailed(source, {BitTorrent::AddTorrentError::Other, reason}); } -void AddTorrentManager::handleDuplicateTorrent(const QString &source +bool AddTorrentManager::handleDuplicateTorrent(const QString &source , const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent) { const bool hasMetadata = torrentDescr.info().has_value(); @@ -170,6 +170,7 @@ void AddTorrentManager::handleDuplicateTorrent(const QString &source const bool isPrivate = existingTorrent->isPrivate() || (hasMetadata && torrentDescr.info()->isPrivate()); QString message; + bool added = false; if (!btSession()->isMergeTrackersEnabled()) { message = tr("Merging of trackers is disabled"); @@ -184,11 +185,16 @@ void AddTorrentManager::handleDuplicateTorrent(const QString &source existingTorrent->addTrackers(torrentDescr.trackers()); existingTorrent->addUrlSeeds(torrentDescr.urlSeeds()); message = tr("Trackers are merged from new source"); + added = true; } LogMsg(tr("Detected an attempt to add a duplicate torrent. Source: %1. Existing torrent: \"%2\". Torrent infohash: %3. Result: %4") .arg(source, existingTorrent->name(), existingTorrent->infoHash().toString(), message)); - emit addTorrentFailed(source, {BitTorrent::AddTorrentError::DuplicateTorrent, message}); + if (!added) + { + emit addTorrentFailed(source, {BitTorrent::AddTorrentError::DuplicateTorrent, message}); + } + return added; } void AddTorrentManager::setTorrentFileGuard(const QString &source, std::shared_ptr torrentFileGuard) @@ -209,8 +215,7 @@ bool AddTorrentManager::processTorrent(const QString &source, const BitTorrent:: if (BitTorrent::Torrent *torrent = btSession()->findTorrent(infoHash)) { // a duplicate torrent is being added - handleDuplicateTorrent(source, torrentDescr, torrent); - return false; + return handleDuplicateTorrent(source, torrentDescr, torrent); } return addTorrentToSession(source, torrentDescr, addTorrentParams); diff --git a/src/base/addtorrentmanager.h b/src/base/addtorrentmanager.h index c0044be65057..f20f5fa2fa0b 100644 --- a/src/base/addtorrentmanager.h +++ b/src/base/addtorrentmanager.h @@ -73,7 +73,7 @@ class AddTorrentManager : public ApplicationComponent bool addTorrentToSession(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr , const BitTorrent::AddTorrentParams &addTorrentParams); void handleAddTorrentFailed(const QString &source, const QString &reason); - void handleDuplicateTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent); + bool handleDuplicateTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent); void setTorrentFileGuard(const QString &source, std::shared_ptr torrentFileGuard); std::shared_ptr releaseTorrentFileGuard(const QString &source); diff --git a/src/gui/guiaddtorrentmanager.cpp b/src/gui/guiaddtorrentmanager.cpp index 6e6b709d7d46..ae5b3b711f05 100644 --- a/src/gui/guiaddtorrentmanager.cpp +++ b/src/gui/guiaddtorrentmanager.cpp @@ -219,12 +219,13 @@ bool GUIAddTorrentManager::processTorrent(const QString &source { torrent->addTrackers(torrentDescr.trackers()); torrent->addUrlSeeds(torrentDescr.urlSeeds()); + return true; } } } else { - handleDuplicateTorrent(source, torrentDescr, torrent); + return handleDuplicateTorrent(source, torrentDescr, torrent); } return false;