File indexing completed on 2024-11-17 04:55:44

0001 /*
0002  *   SPDX-FileCopyrightText: 2021 Mariam Fahmy Sobhy <mariamfahmy66@gmail.com>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include "OstreeFormat.h"
0010 
0011 #include <BackendNotifierModule.h>
0012 
0013 #include <QDebug>
0014 #include <QFileSystemWatcher>
0015 #include <QProcess>
0016 #include <QTimer>
0017 
0018 /* Look for new system updates with rpm-ostree.
0019  * Uses only the rpm-ostree command line to simplify logic for now.
0020  * TODO: Use the DBus interface.
0021  */
0022 class RpmOstreeNotifier : public BackendNotifierModule
0023 {
0024     Q_OBJECT
0025     Q_PLUGIN_METADATA(IID "org.kde.discover.BackendNotifierModule")
0026     Q_INTERFACES(BackendNotifierModule)
0027 public:
0028     explicit RpmOstreeNotifier(QObject *parent = nullptr);
0029 
0030     void recheckSystemUpdateNeeded() override;
0031     bool hasSecurityUpdates() override;
0032     bool hasUpdates() override;
0033     bool needsReboot() const override;
0034 
0035 private:
0036     /* Only run this code if we are on an rpm-ostree managed system */
0037     bool isValid() const;
0038 
0039     /* Called by recheckSystemUpdateNeeded to check for system update when the classic
0040      * ostree format is used. */
0041     void checkSystemUpdateClassic();
0042 
0043     /* Called by recheckSystemUpdateNeeded to check for system update when the OCI
0044      * ostree format is used. */
0045     void checkSystemUpdateOCI();
0046 
0047     /* Store which format is used for the ostree image */
0048     QScopedPointer<::OstreeFormat> m_ostreeFormat;
0049 
0050     /* Store the version of the currently booted deployment */
0051     QString m_version;
0052 
0053     /* Tracks the rpm-ostree command used to check for updates or to look at the
0054      * status. */
0055     QProcess *m_process;
0056 
0057     /* Store standard output from rpm-ostree command line calls */
0058     QByteArray m_stdout;
0059 
0060     /* The update version that we've already found in a previous check. Used to
0061      * only notify once about an update for a given version. */
0062     QString m_updateVersion;
0063 
0064     /* Check if we already have a pending deployment for the version avaialbe
0065      * for update */
0066     void checkForPendingDeployment();
0067 
0068     /* Do we have updates available? */
0069     bool m_hasUpdates;
0070 
0071     /* Do we need to reboot to apply updates? */
0072     bool m_needsReboot;
0073 
0074     /* Watcher to trigger a reboot check when deployments are modified */
0075     QFileSystemWatcher *m_watcher;
0076 
0077     /* Timer triggerred by the above watcher to wait for things to settle down before re-doing a deployment check */
0078     QTimer *m_timer;
0079 };