From 9462685c78b24fd2206b9afa2cdaf9f6fd05a807 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sun, 14 Jul 2019 11:29:49 +0300 Subject: [PATCH] Ignore some actions on uninitialized torrents Some actions can lead to an inconsistent state if applied to an uninitialized torrent, so we just ignore them. --- src/base/bittorrent/torrenthandle.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 061e0a60c..dcf8a7ae7 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -223,7 +223,7 @@ TorrentHandle::TorrentHandle(Session *session, const lt::torrent_handle &nativeH // Resume torrent because it was added in "resumed" state // but it's actually paused during initialization. m_startupState = Starting; - resume(m_needsToStartForced); + resume_impl(m_needsToStartForced); } else { m_startupState = Started; @@ -1298,6 +1298,8 @@ bool TorrentHandle::setCategory(const QString &category) void TorrentHandle::move(QString path) { + if (m_startupState != Started) return; + m_useAutoTMM = false; m_session->handleTorrentSavingModeChanged(this); @@ -1336,6 +1338,7 @@ void TorrentHandle::forceDHTAnnounce() void TorrentHandle::forceRecheck() { + if (m_startupState != Started) return; if (!hasMetadata()) return; m_nativeHandle.force_recheck(); @@ -1433,6 +1436,7 @@ void TorrentHandle::toggleFirstLastPiecePriority() void TorrentHandle::pause() { + if (m_startupState != Started) return; if (isPaused()) return; setAutoManaged(false); @@ -1447,6 +1451,8 @@ void TorrentHandle::pause() void TorrentHandle::resume(bool forced) { + if (m_startupState != Started) return; + resume_impl(forced); } @@ -1492,6 +1498,8 @@ void TorrentHandle::moveStorage(const QString &newPath, bool overwrite) void TorrentHandle::renameFile(const int index, const QString &name) { + if (m_startupState != Started) return; + m_oldPath[LTFileIndex {index}].push_back(filePath(index)); ++m_renameCount; m_nativeHandle.rename_file(index, Utils::Fs::toNativePath(name).toStdString()); @@ -1626,7 +1634,7 @@ void TorrentHandle::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p // Resume torrent because it was added in "resumed" state // but it's actually paused during initialization. m_startupState = Starting; - resume(m_needsToStartForced); + resume_impl(m_needsToStartForced); } else { // Torrent that has missing files is paused.