diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index a72d8917b..3d97d3cfe 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -797,35 +797,41 @@ void bittorrent::saveFastResumeData() { // Stop listening for alerts timerAlerts->stop(); int num_resume_data = 0; + // Pause session s->pause(); std::vector torrents = s->get_torrents(); - for(unsigned int i=0; i::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(!h.is_valid() || !h.has_metadata()) continue; if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue; h.save_resume_data(); ++num_resume_data; } - while (num_resume_data > 0) - { + while (num_resume_data > 0) { alert const* a = s->wait_for_alert(seconds(30)); - if (a == 0) - { + if (a == 0) { std::cerr << " aborting with " << num_resume_data << " outstanding " "torrents to save resume data for" << std::endl; break; } + // Saving fastresume data can fail + if (dynamic_cast(a)) { + --num_resume_data; + s->pop_alert(); + continue; + } save_resume_data_alert const* rd = dynamic_cast(a); if (!rd) { s->pop_alert(); continue; } + // Saving fast resume data was successful --num_resume_data; if (!rd->resume_data) continue; QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QTorrentHandle h(rd->handle); + // Remove old fastresume file if it exists QFile::remove(torrentBackup.path()+QDir::separator()+ h.hash() + ".fastresume"); QString file = h.hash()+".fastresume"; boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary); @@ -860,23 +866,6 @@ void bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) { peerBanMessages.append(QString::fromUtf8("")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8(" - ")+tr("%1 was banned due to corrupt pieces", "x.y.z.w was banned").arg(ip)); } -void bittorrent::saveFastResumeData(QString hash) { - QString file; - QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); - // Extracting resume data - QTorrentHandle h = getTorrentHandle(hash); - if(!h.is_valid()) { - qDebug("/!\\ Error: Invalid handle"); - return; - } - if (h.has_metadata() && h.state() != torrent_status::checking_files && h.state() != torrent_status::queued_for_checking) { - // Remove old .fastresume data in case it exists - QFile::remove(torrentBackup.path()+QDir::separator()+hash + ".fastresume"); - // Write fast resume data - h.save_resume_data(); - } -} - bool bittorrent::isFilePreviewPossible(QString hash) const{ // See if there are supported files in the torrent QTorrentHandle h = getTorrentHandle(hash); @@ -1131,7 +1120,6 @@ void bittorrent::readAlerts() { QTorrentHandle h(p->handle); QString file = h.hash()+".fastresume"; qDebug("Saving fastresume data in %s", file.toUtf8().data()); - TORRENT_ASSERT(p->resume_data); if (p->resume_data) { boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary); diff --git a/src/bittorrent.h b/src/bittorrent.h index 9cead6f7d..6fb2cb7d2 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -115,7 +115,6 @@ class bittorrent : public QObject { void saveDHTEntry(); void preAllocateAllFiles(bool b); void saveFastResumeData(); - void saveFastResumeData(QString hash); void enableDirectoryScanning(QString scan_dir); void disableDirectoryScanning(); void enableIPFilter(QString filter);