Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/base/addtorrentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand All @@ -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> torrentFileGuard)
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/base/addtorrentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AddTorrentManager : public ApplicationComponent<QObject>
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> torrentFileGuard);
std::shared_ptr<TorrentFileGuard> releaseTorrentFileGuard(const QString &source);

Expand Down
3 changes: 2 additions & 1 deletion src/gui/guiaddtorrentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down