Fix update discovery and isolate fingerprint installer permissions
This commit is contained in:
1 parent
7f56368674
commit
61ef199667
14 files changed
+106
-51
No files matched your search
@@ -10,6 +10,7 @@ kcmutils_add_qml_kcm(kcm_fedora_tools
|
||||
toolmodel.h
|
||||
)
|
||||
target_link_libraries(kcm_fedora_tools PRIVATE
|
||||
PkgConfig::RPM
|
||||
Qt6::Core
|
||||
Qt6::Quick
|
||||
KF6::AuthCore
|
||||
|
||||
@@ -142,7 +142,6 @@ void FedoraToolsKcm::refresh(bool refreshMetadata)
|
||||
m_refreshMetadata = refreshMetadata;
|
||||
m_installedPackages.clear();
|
||||
m_availablePackages.clear();
|
||||
m_updates.clear();
|
||||
setMessage({});
|
||||
setBusy(true);
|
||||
|
||||
@@ -316,8 +315,12 @@ void FedoraToolsKcm::queryFinished(int exitCode, QProcess::ExitStatus exitStatus
|
||||
const QByteArray output = m_query.readAllStandardOutput();
|
||||
const QByteArray errorOutput = m_query.readAllStandardError();
|
||||
|
||||
if (exitStatus != QProcess::NormalExit) {
|
||||
setMessage(i18n("Package discovery terminated unexpectedly."), true);
|
||||
// rpm -q reports missing packages on stdout with exit code 1. That is a
|
||||
// normal discovery result; stderr or a failed repository query is not.
|
||||
const QString details = QString::fromUtf8(errorOutput).trimmed();
|
||||
if (exitStatus != QProcess::NormalExit
|
||||
|| (exitCode != 0 && (m_stage == QueryStage::Available || !details.isEmpty() || exitCode != 1))) {
|
||||
setMessage(details.isEmpty() ? i18n("Package discovery failed (%1).", m_query.program()) : details, true);
|
||||
m_stage = QueryStage::Idle;
|
||||
setPackageOperation({}, {});
|
||||
setBusy(false);
|
||||
@@ -342,43 +345,12 @@ void FedoraToolsKcm::queryFinished(int exitCode, QProcess::ExitStatus exitStatus
|
||||
}
|
||||
|
||||
if (m_stage == QueryStage::Available) {
|
||||
if (exitCode != 0) {
|
||||
m_tools.setPackages(m_installedPackages, {});
|
||||
const QString details = QString::fromUtf8(errorOutput).trimmed();
|
||||
setMessage(details.isEmpty() ? i18n("The Fedora Tools repository is unavailable.") : details, true);
|
||||
updateFingerprintStatus();
|
||||
m_stage = QueryStage::Idle;
|
||||
setPackageOperation({}, {});
|
||||
setBusy(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_availablePackages = parsePackageRecords(output);
|
||||
if (m_availablePackages.isEmpty()) {
|
||||
finishRefresh();
|
||||
return;
|
||||
}
|
||||
|
||||
startQuery(QStringLiteral("/usr/bin/dnf5"),
|
||||
{QStringLiteral("--repo=fedora-tools"),
|
||||
QStringLiteral("-q"),
|
||||
QStringLiteral("repoquery"),
|
||||
QStringLiteral("--available"),
|
||||
QStringLiteral("--upgrades"),
|
||||
QStringLiteral("--whatprovides=fedora-tools-tool"),
|
||||
QStringLiteral("--queryformat"),
|
||||
packageFormat},
|
||||
QueryStage::Updates);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_stage == QueryStage::Updates) {
|
||||
if (exitCode == 0) {
|
||||
for (const PackageRecord &package : parsePackageRecords(output)) {
|
||||
m_updates.insert(package.name);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList packageNames;
|
||||
for (const PackageRecord &package : std::as_const(m_availablePackages)) {
|
||||
packageNames.append(package.name);
|
||||
@@ -407,7 +379,7 @@ void FedoraToolsKcm::queryFinished(int exitCode, QProcess::ExitStatus exitStatus
|
||||
|
||||
void FedoraToolsKcm::finishRefresh()
|
||||
{
|
||||
m_tools.setPackages(m_installedPackages, m_availablePackages, m_updates);
|
||||
m_tools.setPackages(m_installedPackages, m_availablePackages);
|
||||
updateFingerprintStatus();
|
||||
m_stage = QueryStage::Idle;
|
||||
setPackageOperation({}, {});
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <KQuickConfigModule>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QSet>
|
||||
#include <QUrl>
|
||||
|
||||
class KJob;
|
||||
@@ -75,7 +74,6 @@ private:
|
||||
Idle,
|
||||
InstalledProviders,
|
||||
Available,
|
||||
Updates,
|
||||
KnownInstalled,
|
||||
};
|
||||
|
||||
@@ -95,7 +93,6 @@ private:
|
||||
QueryStage m_stage = QueryStage::Idle;
|
||||
QList<PackageRecord> m_installedPackages;
|
||||
QList<PackageRecord> m_availablePackages;
|
||||
QSet<QString> m_updates;
|
||||
bool m_refreshMetadata = false;
|
||||
bool m_busy = false;
|
||||
bool m_error = false;
|
||||
|
||||
@@ -10,12 +10,26 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QStandardPaths>
|
||||
#include <rpm/rpmver.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool newerVersion(const QString &available, const QString &installed)
|
||||
{
|
||||
const auto candidate = rpmverParse(available.toUtf8().constData());
|
||||
const auto current = rpmverParse(installed.toUtf8().constData());
|
||||
if (!candidate || !current) {
|
||||
qWarning() << "Cannot compare RPM versions:" << available << installed;
|
||||
}
|
||||
const bool newer = candidate && current && rpmverCmp(candidate, current) > 0;
|
||||
rpmverFree(candidate);
|
||||
rpmverFree(current);
|
||||
return newer;
|
||||
}
|
||||
|
||||
QStringList readConfigurationCommand(const QString &packageName)
|
||||
{
|
||||
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
@@ -119,8 +133,7 @@ QHash<int, QByteArray> ToolModel::roleNames() const
|
||||
}
|
||||
|
||||
void ToolModel::setPackages(const QList<PackageRecord> &installed,
|
||||
const QList<PackageRecord> &available,
|
||||
const QSet<QString> &updates)
|
||||
const QList<PackageRecord> &available)
|
||||
{
|
||||
QMap<QString, Tool> tools;
|
||||
|
||||
@@ -147,7 +160,8 @@ void ToolModel::setPackages(const QList<PackageRecord> &installed,
|
||||
}
|
||||
tool.compatibilityError = incompatible;
|
||||
tool.available = incompatible.isEmpty();
|
||||
tool.updateAvailable = tool.available && tool.installed && updates.contains(package.name);
|
||||
tool.updateAvailable = tool.available && tool.installed
|
||||
&& newerVersion(package.version, tool.version);
|
||||
}
|
||||
|
||||
beginResetModel();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "packageutils.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSet>
|
||||
#include <QStringList>
|
||||
|
||||
struct Tool
|
||||
@@ -48,8 +47,7 @@ public:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
void setPackages(const QList<PackageRecord> &installed,
|
||||
const QList<PackageRecord> &available,
|
||||
const QSet<QString> &updates = {});
|
||||
const QList<PackageRecord> &available);
|
||||
bool mayInstall(const QString &packageName) const;
|
||||
bool mayRemove(const QString &packageName) const;
|
||||
QStringList configurationCommand(const QString &packageName) const;
|
||||
|
||||
Reference in new issue
Block a user