From f99a98306df2f8e60ca5b61d84a093edc9dbc83a Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Fri, 14 Jul 2023 15:33:06 +0300 Subject: [PATCH] Log when duplicate torrents are being added PR #19306. Closes #18458. --- src/base/bittorrent/sessionimpl.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 2e5aec040..58f687ba4 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2680,22 +2680,26 @@ bool SessionImpl::addTorrent_impl(const std::variant &so if (m_loadingTorrents.contains(id) || (infoHash.isHybrid() && m_loadingTorrents.contains(altID))) return false; - if (Torrent *torrent = findTorrent(infoHash); torrent) + if (Torrent *torrent = findTorrent(infoHash)) { // a duplicate torrent is being added - if (torrent->isPrivate()) - return false; - if (hasMetadata) { // Trying to set metadata to existing torrent in case if it has none torrent->setMetadata(std::get(source)); + } + const bool isPrivate = torrent->isPrivate() || (hasMetadata && std::get(source).isPrivate()); + if (isPrivate) + { + LogMsg(tr("Found existing torrent. Trackers cannot be merged because it is a private torrent. Torrent: %1").arg(torrent->name())); + return false; + } + + if (hasMetadata) + { const TorrentInfo &torrentInfo = std::get(source); - if (torrentInfo.isPrivate()) - return false; - // merge trackers and web seeds torrent->addTrackers(torrentInfo.trackers()); torrent->addUrlSeeds(torrentInfo.urlSeeds()); @@ -2709,6 +2713,7 @@ bool SessionImpl::addTorrent_impl(const std::variant &so torrent->addUrlSeeds(magnetUri.urlSeeds()); } + LogMsg(tr("Found existing torrent. Trackers are merged from new source. Torrent: %1").arg(torrent->name())); return false; }