mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 00:47:21 -06:00
Fix torrent checking issues
Start all torrents auto-managed to prevent simultaneous checking of multiple torrents. Handle checking state of paused torrent to prevent it from being resumed when qBittorrent is closed until checking isn't complete.
This commit is contained in:
@@ -192,6 +192,7 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
|
||||
, m_hasRootFolder(params.hasRootFolder)
|
||||
, m_needsToSetFirstLastPiecePriority(false)
|
||||
, m_needsToStartForced(params.forced)
|
||||
, m_pauseWhenReady(params.paused)
|
||||
{
|
||||
if (m_useAutoTMM)
|
||||
m_savePath = Utils::Fs::toNativePath(m_session->categorySavePath(m_category));
|
||||
@@ -217,18 +218,18 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
|
||||
m_hasRootFolder = false;
|
||||
}
|
||||
|
||||
// "started" means "all initialization has completed and torrent has started regular processing".
|
||||
// When torrent added/restored in "paused" state it become "started" immediately after construction.
|
||||
// When it is added/restored in "resumed" state, it become "started" after it is really resumed
|
||||
// (i.e. after receiving "torrent resumed" alert).
|
||||
if (params.paused) {
|
||||
m_startupState = Started;
|
||||
}
|
||||
else if (!params.restored || !hasMetadata()) {
|
||||
// Resume torrent because it was added in "resumed" state
|
||||
// but it's actually paused during initialization
|
||||
m_startupState = Starting;
|
||||
resume(params.forced);
|
||||
if (!hasMetadata()) {
|
||||
// There is nothing to prepare
|
||||
if (!m_pauseWhenReady) {
|
||||
// Resume torrent because it was added in "resumed" state
|
||||
// but it's actually paused during initialization.
|
||||
m_startupState = Starting;
|
||||
resume(m_needsToStartForced);
|
||||
}
|
||||
else {
|
||||
m_startupState = Started;
|
||||
m_pauseWhenReady = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,7 +1276,8 @@ void TorrentHandle::forceRecheck()
|
||||
|
||||
if (isPaused()) {
|
||||
m_nativeHandle.stop_when_ready(true);
|
||||
resume_impl(false);
|
||||
m_nativeHandle.auto_managed(true);
|
||||
m_pauseWhenReady = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1554,17 +1556,22 @@ void TorrentHandle::handleTorrentCheckedAlert(const libtorrent::torrent_checked_
|
||||
Q_UNUSED(p);
|
||||
qDebug("\"%s\" have just finished checking", qUtf8Printable(name()));
|
||||
|
||||
if (m_startupState == NotStarted) {
|
||||
if (!m_hasMissingFiles) {
|
||||
// Resume torrent because it was added in "resumed" state
|
||||
// but it's actually paused during initialization.
|
||||
m_startupState = Starting;
|
||||
resume(m_needsToStartForced);
|
||||
if (m_startupState == Preparing) {
|
||||
if (!m_pauseWhenReady) {
|
||||
if (!m_hasMissingFiles) {
|
||||
// Resume torrent because it was added in "resumed" state
|
||||
// but it's actually paused during initialization.
|
||||
m_startupState = Starting;
|
||||
resume(m_needsToStartForced);
|
||||
}
|
||||
else {
|
||||
// Torrent that has missing files is paused.
|
||||
m_startupState = Started;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Torrent that has missing files is marked as "started"
|
||||
// but it remains paused.
|
||||
m_startupState = Started;
|
||||
m_pauseWhenReady = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1588,10 +1595,10 @@ void TorrentHandle::handleTorrentFinishedAlert(const libtorrent::torrent_finishe
|
||||
Q_UNUSED(p);
|
||||
qDebug("Got a torrent finished alert for \"%s\"", qUtf8Printable(name()));
|
||||
qDebug("Torrent has seed status: %s", m_hasSeedStatus ? "yes" : "no");
|
||||
m_hasMissingFiles = false;
|
||||
if (m_hasSeedStatus) return;
|
||||
|
||||
updateStatus();
|
||||
m_hasMissingFiles = false;
|
||||
m_hasSeedStatus = true;
|
||||
|
||||
adjustActualSavePath();
|
||||
@@ -1615,9 +1622,14 @@ void TorrentHandle::handleTorrentPausedAlert(const libtorrent::torrent_paused_al
|
||||
Q_UNUSED(p);
|
||||
|
||||
if (m_startupState == Started) {
|
||||
updateStatus();
|
||||
m_speedMonitor.reset();
|
||||
m_session->handleTorrentPaused(this);
|
||||
if (!m_pauseWhenReady) {
|
||||
updateStatus();
|
||||
m_speedMonitor.reset();
|
||||
m_session->handleTorrentPaused(this);
|
||||
}
|
||||
else {
|
||||
m_pauseWhenReady = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1639,8 +1651,8 @@ void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data
|
||||
libtorrent::entry &resumeData = useDummyResumeData ? dummyEntry : *(p->resume_data);
|
||||
if (useDummyResumeData) {
|
||||
resumeData["qBt-magnetUri"] = toMagnetUri().toStdString();
|
||||
resumeData["qBt-paused"] = isPaused();
|
||||
resumeData["qBt-forced"] = isForced();
|
||||
resumeData["paused"] = isPaused();
|
||||
resumeData["auto_managed"] = m_nativeStatus.auto_managed;
|
||||
// Both firstLastPiecePriority and sequential need to be stored in the
|
||||
// resume data if there is no metadata, otherwise they won't be
|
||||
// restored if qBittorrent quits before the metadata are retrieved:
|
||||
@@ -1662,6 +1674,14 @@ void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data
|
||||
resumeData["qBt-queuePosition"] = (nativeHandle().queue_position() + 1); // qBt starts queue at 1
|
||||
resumeData["qBt-hasRootFolder"] = m_hasRootFolder;
|
||||
|
||||
if (m_pauseWhenReady) {
|
||||
// We need to redefine these values when torrent starting/rechecking
|
||||
// in "paused" state since native values can be logically wrong
|
||||
// (torrent can be not paused and auto_managed when it is checking).
|
||||
resumeData["paused"] = true;
|
||||
resumeData["auto_managed"] = false;
|
||||
}
|
||||
|
||||
m_session->handleTorrentResumeDataReady(this, resumeData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user