mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
- Fixed possible deadlock when saving fastresume data
This commit is contained in:
parent
d5a4794610
commit
1d31e049a4
2 changed files with 15 additions and 28 deletions
|
@ -797,35 +797,41 @@ void bittorrent::saveFastResumeData() {
|
||||||
// Stop listening for alerts
|
// Stop listening for alerts
|
||||||
timerAlerts->stop();
|
timerAlerts->stop();
|
||||||
int num_resume_data = 0;
|
int num_resume_data = 0;
|
||||||
|
// Pause session
|
||||||
s->pause();
|
s->pause();
|
||||||
std::vector<torrent_handle> torrents = s->get_torrents();
|
std::vector<torrent_handle> torrents = s->get_torrents();
|
||||||
for(unsigned int i=0; i<torrents.size(); ++i) {
|
std::vector<torrent_handle>::iterator torrentIT;
|
||||||
QTorrentHandle h(torrents[i]);
|
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||||
if(!h.is_valid()) continue;
|
QTorrentHandle h = QTorrentHandle(*torrentIT);
|
||||||
//if(h.is_paused()) continue;
|
if(!h.is_valid() || !h.has_metadata()) continue;
|
||||||
if (!h.has_metadata()) continue;
|
|
||||||
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue;
|
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue;
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
++num_resume_data;
|
++num_resume_data;
|
||||||
}
|
}
|
||||||
while (num_resume_data > 0)
|
while (num_resume_data > 0) {
|
||||||
{
|
|
||||||
alert const* a = s->wait_for_alert(seconds(30));
|
alert const* a = s->wait_for_alert(seconds(30));
|
||||||
if (a == 0)
|
if (a == 0) {
|
||||||
{
|
|
||||||
std::cerr << " aborting with " << num_resume_data << " outstanding "
|
std::cerr << " aborting with " << num_resume_data << " outstanding "
|
||||||
"torrents to save resume data for" << std::endl;
|
"torrents to save resume data for" << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Saving fastresume data can fail
|
||||||
|
if (dynamic_cast<save_resume_data_failed_alert const*>(a)) {
|
||||||
|
--num_resume_data;
|
||||||
|
s->pop_alert();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
save_resume_data_alert const* rd = dynamic_cast<save_resume_data_alert const*>(a);
|
save_resume_data_alert const* rd = dynamic_cast<save_resume_data_alert const*>(a);
|
||||||
if (!rd) {
|
if (!rd) {
|
||||||
s->pop_alert();
|
s->pop_alert();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Saving fast resume data was successful
|
||||||
--num_resume_data;
|
--num_resume_data;
|
||||||
if (!rd->resume_data) continue;
|
if (!rd->resume_data) continue;
|
||||||
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
|
||||||
QTorrentHandle h(rd->handle);
|
QTorrentHandle h(rd->handle);
|
||||||
|
// Remove old fastresume file if it exists
|
||||||
QFile::remove(torrentBackup.path()+QDir::separator()+ h.hash() + ".fastresume");
|
QFile::remove(torrentBackup.path()+QDir::separator()+ h.hash() + ".fastresume");
|
||||||
QString file = 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);
|
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("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip));
|
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "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{
|
bool bittorrent::isFilePreviewPossible(QString hash) const{
|
||||||
// See if there are supported files in the torrent
|
// See if there are supported files in the torrent
|
||||||
QTorrentHandle h = getTorrentHandle(hash);
|
QTorrentHandle h = getTorrentHandle(hash);
|
||||||
|
@ -1131,7 +1120,6 @@ void bittorrent::readAlerts() {
|
||||||
QTorrentHandle h(p->handle);
|
QTorrentHandle h(p->handle);
|
||||||
QString file = h.hash()+".fastresume";
|
QString file = h.hash()+".fastresume";
|
||||||
qDebug("Saving fastresume data in %s", file.toUtf8().data());
|
qDebug("Saving fastresume data in %s", file.toUtf8().data());
|
||||||
TORRENT_ASSERT(p->resume_data);
|
|
||||||
if (p->resume_data)
|
if (p->resume_data)
|
||||||
{
|
{
|
||||||
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
|
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
|
||||||
|
|
|
@ -115,7 +115,6 @@ class bittorrent : public QObject {
|
||||||
void saveDHTEntry();
|
void saveDHTEntry();
|
||||||
void preAllocateAllFiles(bool b);
|
void preAllocateAllFiles(bool b);
|
||||||
void saveFastResumeData();
|
void saveFastResumeData();
|
||||||
void saveFastResumeData(QString hash);
|
|
||||||
void enableDirectoryScanning(QString scan_dir);
|
void enableDirectoryScanning(QString scan_dir);
|
||||||
void disableDirectoryScanning();
|
void disableDirectoryScanning();
|
||||||
void enableIPFilter(QString filter);
|
void enableIPFilter(QString filter);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue