Merge pull request #18652 from glassez/v4.5

Backport changes to v4.5.x branch
This commit is contained in:
Vladimir Golovnev
2023-04-04 20:09:47 +03:00
committed by GitHub
5 changed files with 74 additions and 54 deletions

View File

@@ -272,7 +272,7 @@ BitTorrent::DBResumeDataStorage::DBResumeDataStorage(const Path &dbPath, QObject
else
{
const int dbVersion = (!db.record(DB_TABLE_TORRENTS).contains(DB_COLUMN_DOWNLOAD_PATH.name) ? 1 : currentDBVersion());
if (dbVersion != DB_VERSION)
if (dbVersion < DB_VERSION)
updateDB(dbVersion);
}
@@ -531,18 +531,28 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const
{
if (fromVersion == 1)
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_DOWNLOAD_PATH, "TEXT"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
const auto testQuery = u"SELECT COUNT(%1) FROM %2;"_qs
.arg(quoted(DB_COLUMN_DOWNLOAD_PATH.name), quoted(DB_TABLE_TORRENTS));
if (!query.exec(testQuery))
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_DOWNLOAD_PATH, "TEXT"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
}
}
if (fromVersion <= 2)
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_STOP_CONDITION, "TEXT NOT NULL DEFAULT `None`"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
const auto testQuery = u"SELECT COUNT(%1) FROM %2;"_qs
.arg(quoted(DB_COLUMN_STOP_CONDITION.name), quoted(DB_TABLE_TORRENTS));
if (!query.exec(testQuery))
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_STOP_CONDITION, "TEXT NOT NULL DEFAULT `None`"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
}
}
const QString updateMetaVersionQuery = makeUpdateStatement(DB_TABLE_META, {DB_COLUMN_NAME, DB_COLUMN_VALUE});

View File

@@ -5239,10 +5239,13 @@ void SessionImpl::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p)
#endif
const auto removingTorrentDataIter = m_removingTorrents.find(id);
if (removingTorrentDataIter == m_removingTorrents.end())
return;
// torrent_deleted_alert can also be posted due to deletion of partfile. Ignore it in such a case.
if (removingTorrentDataIter->deleteOption == DeleteTorrent)
return;
Utils::Fs::smartRemoveEmptyFolderTree(removingTorrentDataIter->pathToRemove);
LogMsg(tr("Removed torrent and deleted its content. Torrent: \"%1\"").arg(removingTorrentDataIter->name));
m_removingTorrents.erase(removingTorrentDataIter);
@@ -5257,7 +5260,6 @@ void SessionImpl::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed
#endif
const auto removingTorrentDataIter = m_removingTorrents.find(id);
if (removingTorrentDataIter == m_removingTorrents.end())
return;
@@ -5267,7 +5269,7 @@ void SessionImpl::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed
// so we remove the directory ourselves
Utils::Fs::smartRemoveEmptyFolderTree(removingTorrentDataIter->pathToRemove);
LogMsg(tr("Removed torrent but failed to delete its content. Torrent: \"%1\". Error: \"%2\"")
LogMsg(tr("Removed torrent but failed to delete its content and/or partfile. Torrent: \"%1\". Error: \"%2\"")
.arg(removingTorrentDataIter->name, QString::fromLocal8Bit(p->error.message().c_str()))
, Log::WARNING);
}
@@ -5275,6 +5277,7 @@ void SessionImpl::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed
{
LogMsg(tr("Removed torrent. Torrent: \"%1\"").arg(removingTorrentDataIter->name));
}
m_removingTorrents.erase(removingTorrentDataIter);
}

View File

@@ -1841,25 +1841,24 @@ void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p
m_statusUpdatedTriggers.enqueue([this]()
{
m_hasSeedStatus = true;
adjustStorageLocation();
manageIncompleteFiles();
m_session->handleTorrentNeedSaveResumeData(this);
const bool recheckTorrentsOnCompletion = Preferences::instance()->recheckTorrentsOnCompletion();
if (isMoveInProgress() || (m_renameCount > 0))
if (recheckTorrentsOnCompletion && m_unchecked)
{
if (recheckTorrentsOnCompletion)
m_moveFinishedTriggers.enqueue([this]() { forceRecheck(); });
m_moveFinishedTriggers.enqueue([this]() { m_session->handleTorrentFinished(this); });
forceRecheck();
}
else
{
if (recheckTorrentsOnCompletion && m_unchecked)
forceRecheck();
m_session->handleTorrentFinished(this);
m_hasSeedStatus = true;
if (isMoveInProgress() || (m_renameCount > 0))
m_moveFinishedTriggers.enqueue([this]() { m_session->handleTorrentFinished(this); });
else
m_session->handleTorrentFinished(this);
}
});
}

View File

@@ -293,17 +293,18 @@ void OptionsDialog::loadBehaviorTabOptions()
m_ui->checkPreventFromSuspendWhenDownloading->setChecked(pref->preventFromSuspendWhenDownloading());
m_ui->checkPreventFromSuspendWhenSeeding->setChecked(pref->preventFromSuspendWhenSeeding());
m_ui->checkFileLog->setChecked(app()->isFileLoggerEnabled());
const bool fileLogEnabled = app()->isFileLoggerEnabled();
m_ui->checkFileLog->setChecked(fileLogEnabled);
m_ui->textFileLogPath->setDialogCaption(tr("Choose a save directory"));
m_ui->textFileLogPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
m_ui->textFileLogPath->setSelectedPath(app()->fileLoggerPath());
const bool fileLogBackup = app()->isFileLoggerBackup();
m_ui->checkFileLogBackup->setChecked(fileLogBackup);
m_ui->spinFileLogSize->setEnabled(fileLogBackup);
m_ui->spinFileLogSize->setEnabled(fileLogEnabled && fileLogBackup);
const bool fileLogDelete = app()->isFileLoggerDeleteOld();
m_ui->checkFileLogDelete->setChecked(fileLogDelete);
m_ui->spinFileLogAge->setEnabled(fileLogDelete);
m_ui->comboFileLogAgeType->setEnabled(fileLogDelete);
m_ui->spinFileLogAge->setEnabled(fileLogEnabled && fileLogDelete);
m_ui->comboFileLogAgeType->setEnabled(fileLogEnabled && fileLogDelete);
m_ui->spinFileLogSize->setValue(app()->fileLoggerMaxSize() / 1024);
m_ui->spinFileLogAge->setValue(app()->fileLoggerAge());
m_ui->comboFileLogAgeType->setCurrentIndex(app()->fileLoggerAgeType());
@@ -352,7 +353,14 @@ void OptionsDialog::loadBehaviorTabOptions()
m_ui->checkPreventFromSuspendWhenSeeding->setDisabled(true);
#endif
connect(m_ui->checkFileLog, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkFileLog, &QGroupBox::toggled, this, [this](const bool checked)
{
m_ui->spinFileLogSize->setEnabled(checked && m_ui->checkFileLogBackup->isChecked());
const bool bothChecked = checked && m_ui->checkFileLogDelete->isChecked();
m_ui->spinFileLogAge->setEnabled(bothChecked);
m_ui->comboFileLogAgeType->setEnabled(bothChecked);
enableApplyButton();
});
connect(m_ui->textFileLogPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, m_ui->spinFileLogSize, &QWidget::setEnabled);
connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);