Browse Source

Merge pull request #17900 from Chocobo1/alerts

Handle all types of alerts on shutdown
adaptive-webui-19844
Chocobo1 2 years ago committed by GitHub
parent
commit
be0f34a69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      src/base/bittorrent/sessionimpl.cpp

40
src/base/bittorrent/sessionimpl.cpp

@ -2268,7 +2268,7 @@ bool SessionImpl::deleteTorrent(const TorrentID &id, const DeleteOption deleteOp @@ -2268,7 +2268,7 @@ bool SessionImpl::deleteTorrent(const TorrentID &id, const DeleteOption deleteOp
{
// Delete "move storage job" for the deleted torrent
// (note: we shouldn't delete active job)
const auto iter = std::find_if(m_moveStorageQueue.begin() + 1, m_moveStorageQueue.end()
const auto iter = std::find_if((m_moveStorageQueue.begin() + 1), m_moveStorageQueue.end()
, [torrent](const MoveStorageJob &job)
{
return job.torrentHandle == torrent->nativeHandle();
@ -2903,37 +2903,49 @@ void SessionImpl::saveResumeData() @@ -2903,37 +2903,49 @@ void SessionImpl::saveResumeData()
++m_numResumeData;
}
// clear queued storage move jobs except the current ongoing one
if (m_moveStorageQueue.size() > 1)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
m_moveStorageQueue = m_moveStorageQueue.mid(0, 1);
#else
m_moveStorageQueue.resize(1);
#endif
}
QElapsedTimer timer;
timer.start();
while (m_numResumeData > 0)
while ((m_numResumeData > 0) || !m_moveStorageQueue.isEmpty())
{
const lt::seconds waitTime {5};
const lt::seconds expireTime {30};
// only terminate when no storage is moving
if (timer.hasExpired(lt::total_milliseconds(expireTime)) && m_moveStorageQueue.isEmpty())
{
LogMsg(tr("Aborted saving resume data. Number of outstanding torrents: %1").arg(QString::number(m_numResumeData))
, Log::CRITICAL);
break;
}
const std::vector<lt::alert *> alerts = getPendingAlerts(waitTime);
bool hasWantedAlert = false;
for (const lt::alert *a : alerts)
{
if (const int alertType = a->type();
(alertType == lt::save_resume_data_alert::alert_type)
|| (alertType == lt::save_resume_data_failed_alert::alert_type))
(alertType == lt::save_resume_data_alert::alert_type) || (alertType == lt::save_resume_data_failed_alert::alert_type)
|| (alertType == lt::storage_moved_alert::alert_type) || (alertType == lt::storage_moved_failed_alert::alert_type))
{
hasWantedAlert = true;
handleAlert(a);
}
handleAlert(a);
}
if (hasWantedAlert)
{
timer.start();
}
else if (timer.hasExpired(lt::total_milliseconds(expireTime)))
{
LogMsg(tr("Aborted saving resume data. Number of outstanding torrents: %1").arg(QString::number(m_numResumeData))
, Log::CRITICAL);
break;
}
}
}
@ -4675,7 +4687,7 @@ bool SessionImpl::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &new @@ -4675,7 +4687,7 @@ bool SessionImpl::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &new
if (m_moveStorageQueue.size() > 1)
{
auto iter = std::find_if(m_moveStorageQueue.begin() + 1, m_moveStorageQueue.end()
auto iter = std::find_if((m_moveStorageQueue.begin() + 1), m_moveStorageQueue.end()
, [&torrentHandle](const MoveStorageJob &job)
{
return job.torrentHandle == torrentHandle;

Loading…
Cancel
Save