Skip to content

Commit 4b6051f

Browse files
authored
Merge branch 'qbittorrent:master' into allow-multiple-connections-per-pid
2 parents 36eda43 + 52d3a96 commit 4b6051f

24 files changed

Lines changed: 130 additions & 172 deletions

src/app/application.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,13 @@ void Application::setFileLoggerEnabled(const bool value)
477477

478478
Path Application::fileLoggerPath() const
479479
{
480-
return m_storeFileLoggerPath.get(specialFolderLocation(SpecialFolder::Data) / Path(LOG_FOLDER));
480+
return m_storeFileLoggerPath.get(Path(LOG_FOLDER));
481481
}
482482

483483
void Application::setFileLoggerPath(const Path &path)
484484
{
485485
if (m_fileLogger)
486-
m_fileLogger->changePath(path);
486+
m_fileLogger->setPath(path);
487487
m_storeFileLoggerPath = path;
488488
}
489489

@@ -983,10 +983,10 @@ int Application::exec()
983983
m_desktopIntegration->showNotification(tr("Torrent added"), tr("'%1' was added.", "e.g: xxx.avi was added.").arg(torrent->name()));
984984
});
985985
connect(m_addTorrentManager, &AddTorrentManager::addTorrentFailed, this
986-
, [this](const QString &source, const BitTorrent::AddTorrentError &reason)
986+
, [this](const QString &source, const QString &reason)
987987
{
988988
m_desktopIntegration->showNotification(tr("Add torrent failed")
989-
, tr("Couldn't add torrent '%1', reason: %2.").arg(source, reason.message));
989+
, tr("Couldn't add torrent '%1', reason: %2.").arg(source, reason));
990990
});
991991

992992
disconnect(m_desktopIntegration, &DesktopIntegration::activationRequested, this, &Application::createStartupProgressDialog);

src/app/filelogger.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Bittorrent Client using Qt and libtorrent.
3+
* Copyright (C) 2026 Vladimir Golovnev <glassez@yandex.ru>
34
* Copyright (C) 2016 sledgehammer999 <hammered999@gmail.com>
45
*
56
* This program is free software; you can redistribute it and/or
@@ -37,24 +38,23 @@
3738

3839
#include "base/global.h"
3940
#include "base/logger.h"
41+
#include "base/profile.h"
4042
#include "base/utils/fs.h"
4143

42-
namespace
43-
{
44-
const std::chrono::seconds FLUSH_INTERVAL {2};
45-
}
44+
const QString LOG_FILENAME = u"qbittorrent.log"_s;
45+
const std::chrono::seconds FLUSH_INTERVAL {2};
4646

4747
FileLogger::FileLogger(const Path &path, const bool backup
48-
, const int maxSize, const bool deleteOld, const int age
49-
, const FileLogAgeType ageType)
50-
: m_backup(backup)
51-
, m_maxSize(maxSize)
48+
, const int maxSize, const bool deleteOld, const int age
49+
, const FileLogAgeType ageType)
50+
: m_backup {backup}
51+
, m_maxSize {maxSize}
5252
{
5353
m_flusher.setInterval(FLUSH_INTERVAL);
5454
m_flusher.setSingleShot(true);
5555
connect(&m_flusher, &QTimer::timeout, this, &FileLogger::flushLog);
5656

57-
changePath(path);
57+
setPath(path);
5858
if (deleteOld)
5959
this->deleteOld(age, ageType);
6060

@@ -70,26 +70,27 @@ FileLogger::~FileLogger()
7070
closeLogFile();
7171
}
7272

73-
void FileLogger::changePath(const Path &newPath)
73+
void FileLogger::setPath(const Path &newPath)
7474
{
75+
const Path newPathAbs = newPath.isAbsolute() ? newPath : (specialFolderLocation(SpecialFolder::Data) / newPath);
7576
// compare paths as strings to perform case sensitive comparison on all the platforms
76-
if (newPath.data() == m_path.parentPath().data())
77+
if (newPathAbs.data() == m_logsFolderPath.data())
7778
return;
7879

7980
closeLogFile();
8081

81-
m_path = newPath / Path(u"qbittorrent.log"_s);
82-
m_logFile.setFileName(m_path.data());
82+
m_logsFolderPath = newPathAbs;
83+
m_logFile.setFileName((m_logsFolderPath / Path(LOG_FILENAME)).data());
8384

84-
Utils::Fs::mkpath(newPath);
85+
Utils::Fs::mkpath(m_logsFolderPath);
8586
openLogFile();
8687
}
8788

8889
void FileLogger::deleteOld(const int age, const FileLogAgeType ageType)
8990
{
9091
const QDateTime date = QDateTime::currentDateTime();
91-
const QDir dir {m_path.parentPath().data()};
92-
const QFileInfoList fileList = dir.entryInfoList(QStringList(u"qbittorrent.log.bak*"_s)
92+
const QDir dir {m_logsFolderPath.data()};
93+
const QFileInfoList fileList = dir.entryInfoList(QStringList(LOG_FILENAME + u".bak*")
9394
, (QDir::Files | QDir::Writable), (QDir::Time | QDir::Reversed));
9495

9596
for (const QFileInfo &file : fileList)
@@ -149,15 +150,16 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
149150
{
150151
closeLogFile();
151152
int counter = 0;
152-
Path backupLogFilename = m_path + u".bak";
153+
const Path logFilename = m_logsFolderPath / Path(LOG_FILENAME);
154+
Path backupLogFilename = logFilename + u".bak";
153155

154156
while (backupLogFilename.exists())
155157
{
156158
++counter;
157-
backupLogFilename = m_path + u".bak" + QString::number(counter);
159+
backupLogFilename = logFilename + u".bak" + QString::number(counter);
158160
}
159161

160-
Utils::Fs::renameFile(m_path, backupLogFilename);
162+
Utils::Fs::renameFile(logFilename, backupLogFilename);
161163
openLogFile();
162164
}
163165
else

src/app/filelogger.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Bittorrent Client using Qt and libtorrent.
3+
* Copyright (C) 2026 Vladimir Golovnev <glassez@yandex.ru>
34
* Copyright (C) 2016 sledgehammer999 <hammered999@gmail.com>
45
*
56
* This program is free software; you can redistribute it and/or
@@ -39,7 +40,7 @@ namespace Log
3940
struct Msg;
4041
}
4142

42-
class FileLogger : public QObject
43+
class FileLogger final : public QObject
4344
{
4445
Q_OBJECT
4546
Q_DISABLE_COPY_MOVE(FileLogger)
@@ -53,9 +54,9 @@ class FileLogger : public QObject
5354
};
5455

5556
FileLogger(const Path &path, bool backup, int maxSize, bool deleteOld, int age, FileLogAgeType ageType);
56-
~FileLogger();
57+
~FileLogger() override;
5758

58-
void changePath(const Path &newPath);
59+
void setPath(const Path &newPath);
5960
void deleteOld(int age, FileLogAgeType ageType);
6061
void setBackup(bool value);
6162
void setMaxSize(int value);
@@ -68,7 +69,7 @@ private slots:
6869
void openLogFile();
6970
void closeLogFile();
7071

71-
Path m_path;
72+
Path m_logsFolderPath;
7273
bool m_backup;
7374
int m_maxSize;
7475
QFile m_logFile;

src/base/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ add_library(qbt_base STATIC
55
algorithm.h
66
applicationcomponent.h
77
asyncfilestorage.h
8-
bittorrent/addtorrenterror.h
98
bittorrent/addtorrentparams.h
109
bittorrent/announcetimepoint.h
1110
bittorrent/bandwidthscheduler.h

src/base/addtorrentmanager.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#include "addtorrentmanager.h"
3131

32-
#include "base/bittorrent/addtorrenterror.h"
3332
#include "base/bittorrent/infohash.h"
3433
#include "base/bittorrent/session.h"
3534
#include "base/bittorrent/torrentdescriptor.h"
@@ -43,6 +42,7 @@ AddTorrentManager::AddTorrentManager(IApplication *app, BitTorrent::Session *btS
4342
{
4443
Q_ASSERT(btSession);
4544
connect(btSession, &BitTorrent::Session::torrentAdded, this, &AddTorrentManager::onSessionTorrentAdded);
45+
connect(btSession, &BitTorrent::Session::duplicateTorrentDetected, this, &AddTorrentManager::onSessionDuplicateTorrentDetected);
4646
connect(btSession, &BitTorrent::Session::addTorrentFailed, this, &AddTorrentManager::onSessionAddTorrentFailed);
4747
}
4848

@@ -141,7 +141,20 @@ void AddTorrentManager::onSessionTorrentAdded(BitTorrent::Torrent *torrent)
141141
}
142142
}
143143

144-
void AddTorrentManager::onSessionAddTorrentFailed(const BitTorrent::InfoHash &infoHash, const BitTorrent::AddTorrentError &reason)
144+
void AddTorrentManager::onSessionDuplicateTorrentDetected(const BitTorrent::InfoHash &infoHash
145+
, BitTorrent::Torrent *torrent, const QString &message)
146+
{
147+
const QString source = m_sourcesByInfoHash.take(infoHash);
148+
if (source.isEmpty())
149+
return;
150+
151+
std::shared_ptr<TorrentFileGuard> torrentFileGuard = m_guardedTorrentFiles.take(source);
152+
if (torrentFileGuard)
153+
torrentFileGuard->setAutoRemove(false);
154+
emit duplicateTorrentDetected(source, torrent, message);
155+
}
156+
157+
void AddTorrentManager::onSessionAddTorrentFailed(const BitTorrent::InfoHash &infoHash, const QString &reason)
145158
{
146159
if (const QString source = m_sourcesByInfoHash.take(infoHash); !source.isEmpty())
147160
{
@@ -155,7 +168,7 @@ void AddTorrentManager::onSessionAddTorrentFailed(const BitTorrent::InfoHash &in
155168
void AddTorrentManager::handleAddTorrentFailed(const QString &source, const QString &reason)
156169
{
157170
LogMsg(tr("Failed to add torrent. Source: \"%1\". Reason: \"%2\"").arg(source, reason), Log::WARNING);
158-
emit addTorrentFailed(source, {BitTorrent::AddTorrentError::Other, reason});
171+
emit addTorrentFailed(source, reason);
159172
}
160173

161174
void AddTorrentManager::handleDuplicateTorrent(const QString &source
@@ -188,7 +201,7 @@ void AddTorrentManager::handleDuplicateTorrent(const QString &source
188201

189202
LogMsg(tr("Detected an attempt to add a duplicate torrent. Source: %1. Existing torrent: \"%2\". Torrent infohash: %3. Result: %4")
190203
.arg(source, existingTorrent->name(), existingTorrent->infoHash().toString(), message));
191-
emit addTorrentFailed(source, {BitTorrent::AddTorrentError::DuplicateTorrent, message});
204+
emit duplicateTorrentDetected(source, existingTorrent, message);
192205
}
193206

194207
void AddTorrentManager::setTorrentFileGuard(const QString &source, std::shared_ptr<TorrentFileGuard> torrentFileGuard)

src/base/addtorrentmanager.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace BitTorrent
4444
class Session;
4545
class Torrent;
4646
class TorrentDescriptor;
47-
struct AddTorrentError;
4847
}
4948

5049
namespace Net
@@ -67,7 +66,8 @@ class AddTorrentManager : public ApplicationComponent<QObject>
6766

6867
signals:
6968
void torrentAdded(const QString &source, BitTorrent::Torrent *torrent);
70-
void addTorrentFailed(const QString &source, const BitTorrent::AddTorrentError &reason);
69+
void duplicateTorrentDetected(const QString &source, BitTorrent::Torrent *torrent, const QString &message);
70+
void addTorrentFailed(const QString &source, const QString &reason);
7171

7272
protected:
7373
bool addTorrentToSession(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr
@@ -80,7 +80,8 @@ class AddTorrentManager : public ApplicationComponent<QObject>
8080
private:
8181
void onDownloadFinished(const Net::DownloadResult &result);
8282
void onSessionTorrentAdded(BitTorrent::Torrent *torrent);
83-
void onSessionAddTorrentFailed(const BitTorrent::InfoHash &infoHash, const BitTorrent::AddTorrentError &reason);
83+
void onSessionDuplicateTorrentDetected(const BitTorrent::InfoHash &infoHash, BitTorrent::Torrent *torrent, const QString &message);
84+
void onSessionAddTorrentFailed(const BitTorrent::InfoHash &infoHash, const QString &reason);
8485
bool processTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr
8586
, const BitTorrent::AddTorrentParams &addTorrentParams);
8687

src/base/bittorrent/addtorrenterror.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/base/bittorrent/session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "base/pathfwd.h"
3838
#include "base/tagset.h"
39-
#include "addtorrenterror.h"
4039
#include "addtorrentparams.h"
4140
#include "categoryoptions.h"
4241
#include "sharelimits.h"
@@ -488,7 +487,7 @@ namespace BitTorrent
488487

489488
signals:
490489
void startupProgressUpdated(int progress);
491-
void addTorrentFailed(const InfoHash &infoHash, const AddTorrentError &reason);
490+
void addTorrentFailed(const InfoHash &infoHash, const QString &reason);
492491
void allTorrentsFinished();
493492
void categoryAdded(const QString &categoryName);
494493
void categoryRemoved(const QString &categoryName);
@@ -509,6 +508,7 @@ namespace BitTorrent
509508

510509
void torrentAboutToBeRemoved(Torrent *torrent);
511510
void torrentAdded(Torrent *torrent);
511+
void duplicateTorrentDetected(const InfoHash &infoHash, Torrent *torrent, const QString &message);
512512
void torrentCategoryChanged(Torrent *torrent, const QString &oldCategory);
513513
void torrentFinished(Torrent *torrent);
514514
void torrentFinishedChecking(Torrent *torrent);

src/base/bittorrent/sessionimpl.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
27872787
const QString message = tr("Merging of trackers is disabled");
27882788
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3")
27892789
.arg(torrent->name(), torrent->infoHash().toString(), message));
2790-
emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message});
2790+
emit duplicateTorrentDetected(infoHash, torrent, message);
27912791
return false;
27922792
}
27932793

@@ -2797,7 +2797,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
27972797
const QString message = tr("Trackers cannot be merged because it is a private torrent");
27982798
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3")
27992799
.arg(torrent->name(), torrent->infoHash().toString(), message));
2800-
emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message});
2800+
emit duplicateTorrentDetected(infoHash, torrent, message);
28012801
return false;
28022802
}
28032803

@@ -2808,7 +2808,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
28082808
const QString message = tr("Trackers are merged from new source");
28092809
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3")
28102810
.arg(torrent->name(), torrent->infoHash().toString(), message));
2811-
emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message});
2811+
emit duplicateTorrentDetected(infoHash, torrent, message);
28122812
return false;
28132813
}
28142814

@@ -3016,12 +3016,18 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
30163016
if (alert->error)
30173017
{
30183018
const QString msg = QString::fromStdString(alert->message());
3019-
LogMsg(tr("Failed to add torrent. Reason: \"%1\"").arg(msg), Log::WARNING);
3020-
30213019
const InfoHash infoHash = getInfoHash(alert->params);
3022-
const AddTorrentError::Kind errorKind = (alert->error == lt::errors::duplicate_torrent)
3023-
? AddTorrentError::DuplicateTorrent : AddTorrentError::Other;
3024-
emit addTorrentFailed(infoHash, {errorKind, msg});
3020+
if (Torrent *torrent = findTorrent(infoHash); (alert->error == lt::errors::duplicate_torrent) && torrent)
3021+
{
3022+
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3")
3023+
.arg(torrent->name(), torrent->infoHash().toString(), msg));
3024+
emit duplicateTorrentDetected(infoHash, torrent, msg);
3025+
}
3026+
else
3027+
{
3028+
LogMsg(tr("Failed to add torrent. Reason: \"%1\"").arg(msg), Log::WARNING);
3029+
emit addTorrentFailed(infoHash, msg);
3030+
}
30253031
}
30263032
else
30273033
{

0 commit comments

Comments
 (0)