Merge pull request #6262 from evsh/resume-fixes

Resume fixes
This commit is contained in:
sledgehammer999 2017-01-18 22:21:15 +02:00 committed by GitHub
commit b88b7d4af7
4 changed files with 23 additions and 7 deletions

View File

@ -1858,7 +1858,7 @@ void Session::generateResumeData(bool final)
if (torrent->isChecking() || torrent->hasError()) continue;
if (!final && !torrent->needSaveResumeData()) continue;
saveTorrentResumeData(torrent);
saveTorrentResumeData(torrent, final);
qDebug("Saving fastresume data for %s", qPrintable(torrent->name()));
}
}
@ -2782,9 +2782,9 @@ void Session::handleTorrentRatioLimitChanged(TorrentHandle *const torrent)
updateRatioTimer();
}
void Session::saveTorrentResumeData(TorrentHandle *const torrent)
void Session::saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave)
{
torrent->saveResumeData();
torrent->saveResumeData(finalSave);
++m_numResumeData;
}
@ -3077,6 +3077,7 @@ void Session::startUpTorrents()
// Resume downloads
QMap<int, TorrentResumeData> queuedResumeData;
int nextQueuePosition = 1;
int numOfRemappedFiles = 0;
QRegExp rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$"));
foreach (const QString &fastresumeName, fastresumes) {
if (rx.indexIn(fastresumeName) == -1) continue;
@ -3100,11 +3101,23 @@ void Session::startUpTorrents()
}
}
else {
queuedResumeData[queuePosition] = { hash, magnetUri, resumeData, data };
int q = queuePosition;
for(; queuedResumeData.contains(q); ++q) {
}
if (q != queuePosition) {
++numOfRemappedFiles;
}
queuedResumeData[q] = { hash, magnetUri, resumeData, data };
}
}
}
if (numOfRemappedFiles > 0) {
logger->addMessage(
QString(tr("Queue positions were corrected in %1 resume files")).arg(numOfRemappedFiles),
Log::CRITICAL);
}
// starting up downloading torrents (queue position > 0)
foreach (const TorrentResumeData &torrentResumeData, queuedResumeData)
startupTorrent(torrentResumeData);

View File

@ -467,7 +467,7 @@ namespace BitTorrent
void updateRatioTimer();
void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);
void saveTorrentResumeData(TorrentHandle *const torrent);
void saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave = false);
void handleAlert(libtorrent::alert *a);
void dispatchTorrentAlert(libtorrent::alert *a);

View File

@ -485,8 +485,11 @@ bool TorrentHandle::needSaveResumeData() const
SAFE_RETURN(bool, need_save_resume_data, false);
}
void TorrentHandle::saveResumeData()
void TorrentHandle::saveResumeData(bool updateStatus)
{
if (updateStatus) // to update queue_position, see discussion in PR #6154
this->updateStatus();
SAFE_CALL(save_resume_data);
m_needSaveResumeData = false;
}

View File

@ -351,7 +351,7 @@ namespace BitTorrent
void handleTempPathChanged();
void handleCategorySavePathChanged();
void handleAppendExtensionToggled();
void saveResumeData();
void saveResumeData(bool updateStatus = false);
private:
typedef boost::function<void ()> EventTrigger;