From 2ca70cf6cc929c43b2bca49c4793f7222ef5eb22 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 25 Nov 2019 21:37:32 +0800 Subject: [PATCH] Fix stuck in wrong torrent state Before this patch, adding the torrent in https://github.com/qbittorrent/qBittorrent/issues/11511 and the torrrent state will stay in torrent_status::checking_resume_data forever. This is not the correct state since the `torrent_status.errc` field is non-zero and this commit fixes it. --- src/base/bittorrent/session.cpp | 4 ++++ src/base/bittorrent/torrenthandle.cpp | 14 +++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 4bcf5e52d..8adf7dcc0 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4188,6 +4188,10 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) // Send new torrent signal if (!params.restored) emit torrentNew(torrent); + + // Torrent could have error just after adding to libtorrent + if (torrent->hasError()) + LogMsg(tr("Torrent errored. Torrent: \"%1\". Error: %2.").arg(torrent->name(), torrent->error()), Log::WARNING); } void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 67e728a80..05ec4447d 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -899,7 +899,10 @@ TorrentState TorrentHandle::state() const void TorrentHandle::updateState() { - if (m_nativeStatus.state == lt::torrent_status::checking_resume_data) { + if (hasError()) { + m_state = TorrentState::Error; + } + else if (m_nativeStatus.state == lt::torrent_status::checking_resume_data) { m_state = TorrentState::CheckingResumeData; } else if (isMoveInProgress()) { @@ -908,8 +911,6 @@ void TorrentHandle::updateState() else if (isPaused()) { if (hasMissingFiles()) m_state = TorrentState::MissingFiles; - else if (hasError()) - m_state = TorrentState::Error; else m_state = isSeed() ? TorrentState::PausedUploading : TorrentState::PausedDownloading; } @@ -961,12 +962,7 @@ bool TorrentHandle::hasMissingFiles() const bool TorrentHandle::hasError() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return (m_nativeStatus.paused && m_nativeStatus.errc); -#else - return ((m_nativeStatus.flags & lt::torrent_flags::paused) - && m_nativeStatus.errc); -#endif + return static_cast(m_nativeStatus.errc); } bool TorrentHandle::hasFilteredPieces() const