From f6d1fea9b7c58e00c4a674be83a7aa65d1533d49 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 21 Dec 2020 19:50:22 +0300 Subject: [PATCH] Fix bug of "move storage job" can be performed multiple times --- src/base/bittorrent/session.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index a23009fbb..7722bdf18 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4065,6 +4065,8 @@ void Session::moveTorrentStorage(const MoveStorageJob &job) const void Session::handleMoveTorrentStorageJobFinished() { const MoveStorageJob finishedJob = m_moveStorageQueue.takeFirst(); + if (!m_moveStorageQueue.isEmpty()) + moveTorrentStorage(m_moveStorageQueue.first()); const auto iter = std::find_if(m_moveStorageQueue.cbegin(), m_moveStorageQueue.cend() , [&finishedJob](const MoveStorageJob &job) @@ -4076,22 +4078,17 @@ void Session::handleMoveTorrentStorageJobFinished() TorrentHandleImpl *torrent = m_torrents.value(finishedJob.torrentHandle.info_hash()); if (torrent) + { torrent->handleMoveStorageJobFinished(torrentHasOutstandingJob); - - if (!torrentHasOutstandingJob) + } + else if (!torrentHasOutstandingJob) { - if (!torrent) - { - // Last job is completed for torrent that being removing, so actually remove it - const lt::torrent_handle nativeHandle {finishedJob.torrentHandle}; - const RemovingTorrentData &removingTorrentData = m_removingTorrents[nativeHandle.info_hash()]; - if (removingTorrentData.deleteOption == Torrent) - m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_partfile); - } + // Last job is completed for torrent that being removing, so actually remove it + const lt::torrent_handle nativeHandle {finishedJob.torrentHandle}; + const RemovingTorrentData &removingTorrentData = m_removingTorrents[nativeHandle.info_hash()]; + if (removingTorrentData.deleteOption == Torrent) + m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_partfile); } - - if (!m_moveStorageQueue.isEmpty()) - moveTorrentStorage(m_moveStorageQueue.first()); } void Session::handleTorrentTrackerWarning(TorrentHandleImpl *const torrent, const QString &trackerUrl)