diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 238b556dd..3a8bba73e 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1635,7 +1635,8 @@ void QBtSession::saveTempFastResumeData() { try { if (!h.is_valid() || !h.has_metadata() /*|| h.is_seed() || h.is_paused()*/) continue; if (!h.need_save_resume_data()) continue; - if (h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking || h.has_error()) continue; + if (h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking || h.has_error() + || TorrentPersistentData::instance()->getHasMissingFiles(h.hash())) continue; qDebug("Saving fastresume data for %s", qPrintable(h.name())); h.save_resume_data(); }catch(std::exception &e) {} @@ -1667,6 +1668,10 @@ void QBtSession::saveFastResumeData() { // Actually with should save fast resume data for paused files too //if (h.is_paused()) continue; if (h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking || h.has_error()) continue; + if (TorrentPersistentData::instance()->getHasMissingFiles(h.hash())) { + TorrentPersistentData::instance()->setHasMissingFiles(h.hash(), false); + continue; + } h.save_resume_data(); ++num_resume_data; } catch(libtorrent::invalid_handle&) {} @@ -2548,7 +2553,7 @@ void QBtSession::handleTorrentPausedAlert(libtorrent::torrent_paused_alert* p) { if (p->handle.is_valid()) { QTorrentHandle h(p->handle); if (!HiddenData::hasData(h.hash())) { - if (!h.has_error()) + if (!h.has_error() && !TorrentPersistentData::instance()->getHasMissingFiles(h.hash())) h.save_resume_data(); emit pausedTorrent(h); } @@ -2659,11 +2664,11 @@ void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_a QTorrentHandle h(p->handle); if (h.is_valid()) { qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); - if (p->error.value() == 134 && TorrentPersistentData::instance()->isSeed(h.hash()) && h.has_missing_files()) { + if (p->error.value() == errors::mismatching_file_size) { + // Mismatching file size (files were probably moved) const QString hash = h.hash(); - // Mismatching file size (files were probably moved - logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); - TorrentPersistentData::instance()->setErrorState(hash, true); + logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()), Log::CRITICAL); + TorrentPersistentData::instance()->setHasMissingFiles(h.hash(), true); pauseTorrent(hash); } else { logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL); diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index 5a4f3d3b3..a30dadfc4 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -511,7 +511,8 @@ void QTorrentHandle::pause() const { torrent_handle::auto_managed(false); torrent_handle::pause(); - torrent_handle::save_resume_data(); + if (!TorrentPersistentData::instance()->getHasMissingFiles(this->hash())) + torrent_handle::save_resume_data(); } void QTorrentHandle::resume() const diff --git a/src/torrentpersistentdata.cpp b/src/torrentpersistentdata.cpp index e33c258b5..179e87495 100644 --- a/src/torrentpersistentdata.cpp +++ b/src/torrentpersistentdata.cpp @@ -245,7 +245,7 @@ TorrentPersistentData::TorrentPersistentData() , dirty(false) { timer.setSingleShot(true); - timer.setInterval(5*1000); + timer.setInterval(5 * 1000); connect(&timer, SIGNAL(timeout()), SLOT(save())); } @@ -264,12 +264,14 @@ void TorrentPersistentData::save() dirty = false; } -const QVariant TorrentPersistentData::value(const QString &key, const QVariant &defaultValue) const { +const QVariant TorrentPersistentData::value(const QString &key, const QVariant &defaultValue) const +{ QReadLocker locker(&lock); return m_data.value(key, defaultValue); } -void TorrentPersistentData::setValue(const QString &key, const QVariant &value) { +void TorrentPersistentData::setValue(const QString &key, const QVariant &value) +{ QWriteLocker locker(&lock); if (m_data.value(key) == value) return; @@ -467,6 +469,13 @@ void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedS setValue(hash, torrent); } +void TorrentPersistentData::setHasMissingFiles(const QString& hash, bool missing) +{ + QHash torrent = value(hash).toHash(); + torrent["has_missing_files"] = missing; + setValue(hash, torrent); +} + QString TorrentPersistentData::getSavePath(const QString &hash) const { const QHash torrent = value(hash).toHash(); @@ -510,3 +519,9 @@ QString TorrentPersistentData::getMagnetUri(const QString &hash) const Q_ASSERT(torrent.value("is_magnet", false).toBool()); return torrent.value("magnet_uri").toString(); } + +bool TorrentPersistentData::getHasMissingFiles(const QString& hash) +{ + QHash torrent = value(hash).toHash(); + return torrent.value("has_missing_files").toBool(); +} diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 403de28ff..b19f36acf 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -152,6 +152,7 @@ public: void savePriority(const QString &hash, const int &queue_pos); void saveSeedStatus(const QTorrentHandle &h); void saveSeedStatus(const QString &hash, const bool seedStatus); + void setHasMissingFiles(const QString &hash, bool missing); // Getters QString getSavePath(const QString &hash) const; @@ -161,7 +162,7 @@ public: bool isSeed(const QString &hash) const; bool isMagnet(const QString &hash) const; QString getMagnetUri(const QString &hash) const; - + bool getHasMissingFiles(const QString& hash); public slots: void save();