diff --git a/TODO b/TODO index b7db2fc7e..149e0b752 100644 --- a/TODO +++ b/TODO @@ -49,7 +49,7 @@ - Clean up delayed progress column sorting code - Clean up pause after checking code - Test rss now that it has been rewritten - - Wait for torrent_paused_alert before saving fast resume data + - Fix number of finishedChecking torrents - Wait for some bug fixes in libtorrent : - upload/download limit per torrent (Ticket #83) - double free or corruption on exit (Ticket #84) FIXED? @@ -68,6 +68,7 @@ LANGUAGES UPDATED: - Polish *BETA5* beta4->beta5 changelog: +- BUGFIX: Wait for torrent_paused_alert before saving fast resume data - BUGFIX: Finished torrents were still displayed as checking when paused by libtorrent on full disk (hit an assert) - I18N: Updated Italian translation - COSMETIC: Changed the way progress bars are rendered diff --git a/src/GUI.cpp b/src/GUI.cpp index 15ce1119e..1cac7fd40 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -211,7 +211,6 @@ GUI::~GUI(){ delete finishedTorrentTab; delete checkConnect; delete refresher; - delete BTSession; if(systrayIntegration){ delete myTrayIcon; delete myTrayIconMenu; @@ -228,6 +227,7 @@ GUI::~GUI(){ delete switchDownShortcut; delete switchUpShortcut; delete switchRSSShortcut; + delete BTSession; } void GUI::on_actionWebsite_triggered(){ diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 877eef700..795bb0524 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -188,6 +188,10 @@ void bittorrent::deleteTorrent(QString hash, bool permanent){ int index = fullAllocationModeList.indexOf(hash); if(index != -1) fullAllocationModeList.removeAt(index); + // Remove it from pausedTorrents list + index = pausedTorrents.indexOf(hash); + if(index != -1) + pausedTorrents.removeAt(index); if(permanent){ // Remove from Hard drive qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName)); @@ -242,6 +246,10 @@ bool bittorrent::resumeTorrent(QString hash){ torrentsToPauseAfterChecking.removeAt(index); success = true; } + // Remove it from pausedTorrents list + index = pausedTorrents.indexOf(hash); + if(index != -1) + pausedTorrents.removeAt(index); return success; } @@ -646,6 +654,10 @@ void bittorrent::saveDownloadUploadForTorrent(QString hash){ ratio_file.close(); } +bool bittorrent::receivedPausedAlert(QString hash) const{ + return (pausedTorrents.indexOf(hash) != -1); +} + // Save fastresume data for all torrents // and remove them from the session void bittorrent::saveFastResumeAndRatioData(){ @@ -667,9 +679,13 @@ void bittorrent::saveFastResumeAndRatioData(){ } // Pause download (needed before fast resume writing) h.pause(); + QString fileHash = QString(misc::toString(h.info_hash()).c_str()); + while(!receivedPausedAlert(fileHash)){ + SleeperThread::msleep(500); + readAlerts(); + } // Extracting resume data if (h.has_metadata()){ - QString fileHash = QString(misc::toString(h.info_hash()).c_str()); if(QFile::exists(torrentBackup.path()+QDir::separator()+fileHash+".torrent")){ // Remove old .fastresume data in case it exists QFile::remove(torrentBackup.path()+QDir::separator()+fileHash + ".fastresume"); @@ -908,10 +924,17 @@ void bittorrent::readAlerts(){ emit trackerAuthenticationRequired(p->handle); } } + else if (torrent_paused_alert* p = dynamic_cast(a.get())){ + QString hash = QString(misc::toString(p->handle.info_hash()).c_str()); + qDebug("Received torrent_paused_alert for %s", (const char*)hash.toUtf8()); + Q_ASSERT(!pausedTorrents.contains(hash)); + pausedTorrents << hash; + } else if (peer_blocked_alert* p = dynamic_cast(a.get())){ emit peerBlocked(QString(p->ip.to_string().c_str())); } else if (fastresume_rejected_alert* p = dynamic_cast(a.get())){ + qDebug("/!\\ Fast resume failed for %s, reason: %s", p->handle.name().c_str(), p->msg().c_str()); emit fastResumeDataRejected(QString(p->handle.name().c_str())); } else if (url_seed_alert* p = dynamic_cast(a.get())){ diff --git a/src/bittorrent.h b/src/bittorrent.h index 58a690d94..73ba587f0 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -56,6 +56,7 @@ class bittorrent : public QObject{ QList fullAllocationModeList; QHash > > trackersErrors; deleteThread *deleter; + QList pausedTorrents; protected: QString getSavePath(QString hash); @@ -82,6 +83,7 @@ class bittorrent : public QObject{ float getRealRatio(QString hash) const; session* getSession() const; QList > getTrackersErrors(QString hash) const; + bool receivedPausedAlert(QString hash) const; public slots: void addTorrent(QString path, bool fromScanDir = false, bool onStartup = false, QString from_url = QString());