1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-09 22:37:59 +00:00

Merge pull request #13658 from glassez/recheck

Don't resume "paused" torrents when put into "checking" state by libtorrent
This commit is contained in:
Vladimir Golovnev 2020-10-28 08:45:35 +03:00 committed by GitHub
commit 571aaea3e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 62 deletions

View File

@ -49,17 +49,6 @@ NativeTorrentExtension::NativeTorrentExtension(const lt::torrent_handle &torrent
{ {
} }
// This method is called when state of torrent is changed
void NativeTorrentExtension::on_state(const lt::torrent_status::state_t state)
{
// When a torrent enters "checking files" state while paused, we temporarily resume it
// (really we just allow libtorrent to resume it by enabling auto management for it).
if (state == lt::torrent_status::checking_files) {
if (isPaused(m_torrentHandle.status({})))
m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
}
}
bool NativeTorrentExtension::on_pause() bool NativeTorrentExtension::on_pause()
{ {
if (!isAutoManaged(m_torrentHandle.status({}))) if (!isAutoManaged(m_torrentHandle.status({})))

View File

@ -37,7 +37,6 @@ public:
explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle); explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle);
private: private:
void on_state(lt::torrent_status::state_t state) override;
bool on_pause() override; bool on_pause() override;
lt::torrent_handle m_torrentHandle; lt::torrent_handle m_torrentHandle;

View File

@ -743,7 +743,22 @@ void TorrentHandleImpl::updateState()
if (m_nativeStatus.state == lt::torrent_status::checking_resume_data) { if (m_nativeStatus.state == lt::torrent_status::checking_resume_data) {
m_state = TorrentState::CheckingResumeData; m_state = TorrentState::CheckingResumeData;
} }
else if (m_nativeStatus.state == lt::torrent_status::checking_files) { else if (isPaused()) {
if (isMoveInProgress()) {
m_state = TorrentState::Moving;
}
else if (hasMissingFiles()) {
m_state = TorrentState::MissingFiles;
}
else if (hasError()) {
m_state = TorrentState::Error;
}
else {
m_state = isSeed() ? TorrentState::PausedUploading : TorrentState::PausedDownloading;
}
}
else {
if (m_nativeStatus.state == lt::torrent_status::checking_files) {
m_state = m_hasSeedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading; m_state = m_hasSeedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
} }
else if (m_nativeStatus.state == lt::torrent_status::allocating) { else if (m_nativeStatus.state == lt::torrent_status::allocating) {
@ -752,14 +767,11 @@ void TorrentHandleImpl::updateState()
else if (isMoveInProgress()) { else if (isMoveInProgress()) {
m_state = TorrentState::Moving; m_state = TorrentState::Moving;
} }
else if (hasError()) {
m_state = TorrentState::Error;
}
else if (hasMissingFiles()) { else if (hasMissingFiles()) {
m_state = TorrentState::MissingFiles; m_state = TorrentState::MissingFiles;
} }
else if (isPaused()) { else if (hasError()) {
m_state = isSeed() ? TorrentState::PausedUploading : TorrentState::PausedDownloading; m_state = TorrentState::Error;
} }
else if (m_session->isQueueingSystemEnabled() && isQueued() && !isChecking()) { else if (m_session->isQueueingSystemEnabled() && isQueued() && !isChecking()) {
m_state = isSeed() ? TorrentState::QueuedUploading : TorrentState::QueuedDownloading; m_state = isSeed() ? TorrentState::QueuedUploading : TorrentState::QueuedDownloading;
@ -788,6 +800,7 @@ void TorrentHandleImpl::updateState()
} }
} }
} }
}
bool TorrentHandleImpl::hasMetadata() const bool TorrentHandleImpl::hasMetadata() const
{ {
@ -1194,6 +1207,12 @@ void TorrentHandleImpl::forceRecheck()
m_nativeHandle.force_recheck(); m_nativeHandle.force_recheck();
m_unchecked = false; m_unchecked = false;
if (isPaused()) {
// When "force recheck" is applied on paused torrent, we temporarily resume it
// (really we just allow libtorrent to resume it by enabling auto management for it).
m_nativeHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
}
} }
void TorrentHandleImpl::setSequentialDownload(const bool enable) void TorrentHandleImpl::setSequentialDownload(const bool enable)
@ -1449,17 +1468,6 @@ void TorrentHandleImpl::handleSaveResumeDataAlert(const lt::save_resume_data_ale
m_ltAddTorrentParams.added_time = addedTime().toSecsSinceEpoch(); m_ltAddTorrentParams.added_time = addedTime().toSecsSinceEpoch();
m_ltAddTorrentParams.save_path = Profile::instance()->toPortablePath( m_ltAddTorrentParams.save_path = Profile::instance()->toPortablePath(
QString::fromStdString(m_ltAddTorrentParams.save_path)).toStdString(); QString::fromStdString(m_ltAddTorrentParams.save_path)).toStdString();
if (!m_hasMissingFiles) {
m_ltAddTorrentParams.flags = m_nativeStatus.flags;
if (m_nativeStatus.flags & lt::torrent_flags::stop_when_ready) {
// 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).
m_ltAddTorrentParams.flags |= lt::torrent_flags::paused;
m_ltAddTorrentParams.flags &= ~lt::torrent_flags::auto_managed;
m_ltAddTorrentParams.flags &= ~lt::torrent_flags::stop_when_ready;
}
}
auto resumeDataPtr = std::make_shared<lt::entry>(lt::write_resume_data(m_ltAddTorrentParams)); auto resumeDataPtr = std::make_shared<lt::entry>(lt::write_resume_data(m_ltAddTorrentParams));
lt::entry &resumeData = *resumeDataPtr; lt::entry &resumeData = *resumeDataPtr;