Browse Source

Don't touch torrents whose files are missing (like when their drive isn't plugged in).

Closes #342 #2308 2469.
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
45b2432513
  1. 17
      src/qtlibtorrent/qbtsession.cpp
  2. 3
      src/qtlibtorrent/qtorrenthandle.cpp
  3. 21
      src/torrentpersistentdata.cpp
  4. 3
      src/torrentpersistentdata.h

17
src/qtlibtorrent/qbtsession.cpp

@ -1635,7 +1635,8 @@ void QBtSession::saveTempFastResumeData() {
try { try {
if (!h.is_valid() || !h.has_metadata() /*|| h.is_seed() || h.is_paused()*/) continue; if (!h.is_valid() || !h.has_metadata() /*|| h.is_seed() || h.is_paused()*/) continue;
if (!h.need_save_resume_data()) 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())); qDebug("Saving fastresume data for %s", qPrintable(h.name()));
h.save_resume_data(); h.save_resume_data();
}catch(std::exception &e) {} }catch(std::exception &e) {}
@ -1667,6 +1668,10 @@ void QBtSession::saveFastResumeData() {
// Actually with should save fast resume data for paused files too // Actually with should save fast resume data for paused files too
//if (h.is_paused()) continue; //if (h.is_paused()) 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()) continue;
if (TorrentPersistentData::instance()->getHasMissingFiles(h.hash())) {
TorrentPersistentData::instance()->setHasMissingFiles(h.hash(), false);
continue;
}
h.save_resume_data(); h.save_resume_data();
++num_resume_data; ++num_resume_data;
} catch(libtorrent::invalid_handle&) {} } catch(libtorrent::invalid_handle&) {}
@ -2548,7 +2553,7 @@ void QBtSession::handleTorrentPausedAlert(libtorrent::torrent_paused_alert* p) {
if (p->handle.is_valid()) { if (p->handle.is_valid()) {
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if (!HiddenData::hasData(h.hash())) { if (!HiddenData::hasData(h.hash())) {
if (!h.has_error()) if (!h.has_error() && !TorrentPersistentData::instance()->getHasMissingFiles(h.hash()))
h.save_resume_data(); h.save_resume_data();
emit pausedTorrent(h); emit pausedTorrent(h);
} }
@ -2659,11 +2664,11 @@ void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_a
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if (h.is_valid()) { if (h.is_valid()) {
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); 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(); 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()), Log::CRITICAL);
logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); TorrentPersistentData::instance()->setHasMissingFiles(h.hash(), true);
TorrentPersistentData::instance()->setErrorState(hash, true);
pauseTorrent(hash); pauseTorrent(hash);
} else { } else {
logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL); logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL);

3
src/qtlibtorrent/qtorrenthandle.cpp

@ -511,7 +511,8 @@ void QTorrentHandle::pause() const
{ {
torrent_handle::auto_managed(false); torrent_handle::auto_managed(false);
torrent_handle::pause(); torrent_handle::pause();
torrent_handle::save_resume_data(); if (!TorrentPersistentData::instance()->getHasMissingFiles(this->hash()))
torrent_handle::save_resume_data();
} }
void QTorrentHandle::resume() const void QTorrentHandle::resume() const

21
src/torrentpersistentdata.cpp

@ -245,7 +245,7 @@ TorrentPersistentData::TorrentPersistentData()
, dirty(false) , dirty(false)
{ {
timer.setSingleShot(true); timer.setSingleShot(true);
timer.setInterval(5*1000); timer.setInterval(5 * 1000);
connect(&timer, SIGNAL(timeout()), SLOT(save())); connect(&timer, SIGNAL(timeout()), SLOT(save()));
} }
@ -264,12 +264,14 @@ void TorrentPersistentData::save()
dirty = false; 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); QReadLocker locker(&lock);
return m_data.value(key, defaultValue); 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); QWriteLocker locker(&lock);
if (m_data.value(key) == value) if (m_data.value(key) == value)
return; return;
@ -467,6 +469,13 @@ void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedS
setValue(hash, torrent); setValue(hash, torrent);
} }
void TorrentPersistentData::setHasMissingFiles(const QString& hash, bool missing)
{
QHash<QString, QVariant> torrent = value(hash).toHash();
torrent["has_missing_files"] = missing;
setValue(hash, torrent);
}
QString TorrentPersistentData::getSavePath(const QString &hash) const QString TorrentPersistentData::getSavePath(const QString &hash) const
{ {
const QHash<QString, QVariant> torrent = value(hash).toHash(); const QHash<QString, QVariant> torrent = value(hash).toHash();
@ -510,3 +519,9 @@ QString TorrentPersistentData::getMagnetUri(const QString &hash) const
Q_ASSERT(torrent.value("is_magnet", false).toBool()); Q_ASSERT(torrent.value("is_magnet", false).toBool());
return torrent.value("magnet_uri").toString(); return torrent.value("magnet_uri").toString();
} }
bool TorrentPersistentData::getHasMissingFiles(const QString& hash)
{
QHash<QString, QVariant> torrent = value(hash).toHash();
return torrent.value("has_missing_files").toBool();
}

3
src/torrentpersistentdata.h

@ -152,6 +152,7 @@ public:
void savePriority(const QString &hash, const int &queue_pos); void savePriority(const QString &hash, const int &queue_pos);
void saveSeedStatus(const QTorrentHandle &h); void saveSeedStatus(const QTorrentHandle &h);
void saveSeedStatus(const QString &hash, const bool seedStatus); void saveSeedStatus(const QString &hash, const bool seedStatus);
void setHasMissingFiles(const QString &hash, bool missing);
// Getters // Getters
QString getSavePath(const QString &hash) const; QString getSavePath(const QString &hash) const;
@ -161,7 +162,7 @@ public:
bool isSeed(const QString &hash) const; bool isSeed(const QString &hash) const;
bool isMagnet(const QString &hash) const; bool isMagnet(const QString &hash) const;
QString getMagnetUri(const QString &hash) const; QString getMagnetUri(const QString &hash) const;
bool getHasMissingFiles(const QString& hash);
public slots: public slots:
void save(); void save();

Loading…
Cancel
Save