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

Closes #342 #2308 2469.
This commit is contained in:
sledgehammer999 2015-01-08 21:19:46 +02:00
parent 95c75bb8c8
commit 45b2432513
4 changed files with 33 additions and 11 deletions

View file

@ -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);

View file

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

View file

@ -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<QString, QVariant> torrent = value(hash).toHash();
torrent["has_missing_files"] = missing;
setValue(hash, torrent);
}
QString TorrentPersistentData::getSavePath(const QString &hash) const
{
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());
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();
}

View file

@ -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();