Browse Source

Don't force update torrent status

adaptive-webui-19844
Vladimir Golovnev (Glassez) 3 years ago
parent
commit
c740d105c9
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 15
      src/base/bittorrent/session.cpp
  2. 2
      src/base/bittorrent/session.h
  3. 18
      src/base/bittorrent/torrentimpl.cpp
  4. 3
      src/base/bittorrent/torrentimpl.h

15
src/base/bittorrent/session.cpp

@ -4256,7 +4256,7 @@ bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath
}); });
const bool torrentHasOutstandingJob = (iter != m_moveStorageQueue.end()); const bool torrentHasOutstandingJob = (iter != m_moveStorageQueue.end());
torrent->handleMoveStorageJobFinished(torrentHasOutstandingJob); torrent->handleMoveStorageJobFinished(currentLocation, torrentHasOutstandingJob);
} }
} }
@ -4307,7 +4307,7 @@ void Session::moveTorrentStorage(const MoveStorageJob &job) const
? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace)); ? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace));
} }
void Session::handleMoveTorrentStorageJobFinished() void Session::handleMoveTorrentStorageJobFinished(const Path &newPath)
{ {
const MoveStorageJob finishedJob = m_moveStorageQueue.takeFirst(); const MoveStorageJob finishedJob = m_moveStorageQueue.takeFirst();
if (!m_moveStorageQueue.isEmpty()) if (!m_moveStorageQueue.isEmpty())
@ -4324,7 +4324,7 @@ void Session::handleMoveTorrentStorageJobFinished()
TorrentImpl *torrent = m_torrents.value(finishedJob.torrentHandle.info_hash()); TorrentImpl *torrent = m_torrents.value(finishedJob.torrentHandle.info_hash());
if (torrent) if (torrent)
{ {
torrent->handleMoveStorageJobFinished(torrentHasOutstandingJob); torrent->handleMoveStorageJobFinished(newPath, torrentHasOutstandingJob);
} }
else if (!torrentHasOutstandingJob) else if (!torrentHasOutstandingJob)
{ {
@ -5295,7 +5295,7 @@ void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
const QString torrentName = (torrent ? torrent->name() : id.toString()); const QString torrentName = (torrent ? torrent->name() : id.toString());
LogMsg(tr("Moved torrent successfully. Torrent: \"%1\". Destination: \"%2\"").arg(torrentName, newPath.toString())); LogMsg(tr("Moved torrent successfully. Torrent: \"%1\". Destination: \"%2\"").arg(torrentName, newPath.toString()));
handleMoveTorrentStorageJobFinished(); handleMoveTorrentStorageJobFinished(newPath);
} }
void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p) void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p)
@ -5313,12 +5313,13 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
TorrentImpl *torrent = m_torrents.value(id); TorrentImpl *torrent = m_torrents.value(id);
const QString torrentName = (torrent ? torrent->name() : id.toString()); const QString torrentName = (torrent ? torrent->name() : id.toString());
const QString currentLocation = QString::fromStdString(p->handle.status(lt::torrent_handle::query_save_path).save_path); const Path currentLocation = (torrent ? torrent->actualStorageLocation()
: Path(p->handle.status(lt::torrent_handle::query_save_path).save_path));
const QString errorMessage = QString::fromStdString(p->message()); const QString errorMessage = QString::fromStdString(p->message());
LogMsg(tr("Failed to move torrent. Torrent: \"%1\". Source: \"%2\". Destination: \"%3\". Reason: \"%4\"") LogMsg(tr("Failed to move torrent. Torrent: \"%1\". Source: \"%2\". Destination: \"%3\". Reason: \"%4\"")
.arg(torrentName, currentLocation, currentJob.path.toString(), errorMessage), Log::WARNING); .arg(torrentName, currentLocation.toString(), currentJob.path.toString(), errorMessage), Log::WARNING);
handleMoveTorrentStorageJobFinished(); handleMoveTorrentStorageJobFinished(currentLocation);
} }
void Session::handleStateUpdateAlert(const lt::state_update_alert *p) void Session::handleStateUpdateAlert(const lt::state_update_alert *p)

2
src/base/bittorrent/session.h

@ -661,7 +661,7 @@ namespace BitTorrent
std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const; std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const;
void moveTorrentStorage(const MoveStorageJob &job) const; void moveTorrentStorage(const MoveStorageJob &job) const;
void handleMoveTorrentStorageJobFinished(); void handleMoveTorrentStorageJobFinished(const Path &newPath);
void loadCategories(); void loadCategories();
void storeCategories() const; void storeCategories() const;

18
src/base/bittorrent/torrentimpl.cpp

@ -1654,7 +1654,7 @@ void TorrentImpl::moveStorage(const Path &newPath, const MoveStorageMode mode)
if (m_session->addMoveTorrentStorageJob(this, newPath, mode)) if (m_session->addMoveTorrentStorageJob(this, newPath, mode))
{ {
m_storageIsMoving = true; m_storageIsMoving = true;
updateStatus(); updateState();
} }
} }
@ -1670,13 +1670,16 @@ void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus)
updateStatus(nativeStatus); updateStatus(nativeStatus);
} }
void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob) void TorrentImpl::handleMoveStorageJobFinished(const Path &path, const bool hasOutstandingJob)
{ {
m_session->handleTorrentNeedSaveResumeData(this); m_session->handleTorrentNeedSaveResumeData(this);
m_storageIsMoving = hasOutstandingJob; m_storageIsMoving = hasOutstandingJob;
updateStatus(); if (actualStorageLocation() != path)
m_session->handleTorrentSavePathChanged(this); {
m_nativeStatus.save_path = path.toString().toStdString();
m_session->handleTorrentSavePathChanged(this);
}
if (!m_storageIsMoving) if (!m_storageIsMoving)
{ {
@ -1690,7 +1693,7 @@ void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob)
} }
while ((m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty()) while ((m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
m_moveFinishedTriggers.takeFirst()(); std::invoke(m_moveFinishedTriggers.dequeue());
} }
} }
@ -2106,11 +2109,6 @@ bool TorrentImpl::isMoveInProgress() const
return m_storageIsMoving; return m_storageIsMoving;
} }
void TorrentImpl::updateStatus()
{
updateStatus(m_nativeHandle.status());
}
void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus) void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus)
{ {
m_pieces.clear(); m_pieces.clear();

3
src/base/bittorrent/torrentimpl.h

@ -239,14 +239,13 @@ namespace BitTorrent
void handleCategoryOptionsChanged(); void handleCategoryOptionsChanged();
void handleAppendExtensionToggled(); void handleAppendExtensionToggled();
void saveResumeData(); void saveResumeData();
void handleMoveStorageJobFinished(bool hasOutstandingJob); void handleMoveStorageJobFinished(const Path &path, bool hasOutstandingJob);
void fileSearchFinished(const Path &savePath, const PathList &fileNames); void fileSearchFinished(const Path &savePath, const PathList &fileNames);
void updatePeerCount(const QString &trackerUrl, const lt::tcp::endpoint &endpoint, int count); void updatePeerCount(const QString &trackerUrl, const lt::tcp::endpoint &endpoint, int count);
private: private:
using EventTrigger = std::function<void ()>; using EventTrigger = std::function<void ()>;
void updateStatus();
void updateStatus(const lt::torrent_status &nativeStatus); void updateStatus(const lt::torrent_status &nativeStatus);
void updateState(); void updateState();

Loading…
Cancel
Save