File 0001-Add-method-to-query-if-polkit-is-installed-correctly.patch of Package kpmcore

From 65f986dc29c7181410c929da8c34a6e64a6314c3 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabrava@kde.org>
Date: Mon, 29 Nov 2021 11:14:57 -0300
Subject: [PATCH] Add method to query if polkit is installed correctly

The std::cout and qDebugs on the external command helper is
not visible to the user as it runs in another process via dbus
this is highly annoying if you want to be able to discover what's
wrong on the command line.

A method that checks if the file is in the right place should be
called by the users of this library
---
 src/backend/corebackend.cpp | 16 ++++++++++++++++
 src/backend/corebackend.h   |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/src/backend/corebackend.cpp b/src/backend/corebackend.cpp
index 295a631..a8bf28e 100644
--- a/src/backend/corebackend.cpp
+++ b/src/backend/corebackend.cpp
@@ -14,6 +14,8 @@
 #include "util/globallog.h"
 
 #include <QDebug>
+#include <QFileInfo>
+#include <KLocalizedString>
 
 struct CoreBackendPrivate
 {
@@ -29,6 +31,20 @@ CoreBackend::~CoreBackend()
 {
 }
 
+bool CoreBackend::isPolkitInstalledCorrectly() {
+    // Assume PACKAGE_DATA_DIR is /usr/share, this is defined on polkit on buildtime so this might be wrong.
+    // This is a warning, not a hard failure, so it does not matter much.
+    QFileInfo fInfo(QStringLiteral("/usr/share/polkit-1/actions/org.kde.kpmcore.externalcommand.policy"));
+
+    // TODO: Port kpm to qCDebug, currently everything is debug.
+    if (!fInfo.exists()) {
+        qDebug() << "Installation might be wrong, we can't locate `org.kde.kpmcore.externalcommand.policy` on the polkit actions folder.";
+        qDebug() << "Please check if your Installation is on a different prefix and copy it to /usr/share/polkit-1/actions";
+        qDebug() << "That's specified for your distro. Since this is distro specific, you need to look at your distribution documentation.";
+    }
+    return fInfo.exists();
+}
+
 void CoreBackend::emitProgress(int i)
 {
     Q_EMIT progress(i);
diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h
index c828a1b..ec28e73 100644
--- a/src/backend/corebackend.h
+++ b/src/backend/corebackend.h
@@ -170,6 +170,8 @@ public:
       */
     virtual void emitScanProgress(const QString& deviceNode, int i);
 
+    static bool isPolkitInstalledCorrectly();
+
 protected:
     static void setPartitionTableForDevice(Device& d, PartitionTable* p);
     static void setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_primaries);
-- 
GitLab

openSUSE Build Service is sponsored by