From 5f50048cb2034be5d11c9cc2368146a32f8aa72d Mon Sep 17 00:00:00 2001 From: nephros Date: Mon, 10 Jul 2023 09:07:32 +0200 Subject: [PATCH] Squashed commit of recover-failures commit 9627714e78ab2be482ff326b5a108379e3823d11 Merge: 50d3293 e74cf3e Author: nephros Date: Tue Jun 13 23:54:10 2023 +0200 Merge branch 'master' into recover-failures commit 50d3293be0601b2090ab5066698f4eaac6b0d76f Author: nephros Date: Thu Jun 1 08:29:02 2023 +0200 [tool]: fix syntax commit ac9b31c70e7d81545c900f8dc6c043e765d63342 Merge: d24ee1e 3974d0f Author: nephros Date: Thu Jun 1 08:25:36 2023 +0200 Merge branch 'recover-failures' of git+ssh://github.com/nephros/patchmanager into recover-failures commit 3974d0f0aedbb6db5c94ff3608237dc61c2f213c Merge: 7c6611a ae85a89 Author: Peter G Date: Tue May 30 05:16:55 2023 +0000 Merge branch 'master' into recover-failures commit d24ee1e9f6df572a07d3e67c49f48be10bce2ed8 Author: nephros Date: Fri May 26 12:24:40 2023 +0200 refresh after setting good list commit 0fe5d479e25c454d2b64f208ad633478a4b34ffc Author: nephros Date: Fri May 26 12:24:11 2023 +0200 only set good patches if we have any commit 7c6611a1ae7b482b14eb7a290d1d4406049faa98 Author: nephros Date: Fri May 26 12:14:47 2023 +0200 [trivial] whitespace-align help output commit a73a4fc5d9521165bbb6571c07a5edd9b1ca855c Author: nephros Date: Fri May 26 12:14:20 2023 +0200 Add "load known-good" to command line options commit 3acc095ecb2336bed66056cac8be18751ec88b6d Author: nephros Date: Fri May 26 10:37:34 2023 +0200 fixup! Add call to save current set as KnownGood commit adaed74a9be0b4ecd4d438c26d380760573dee7a Author: nephros Date: Fri May 26 10:27:46 2023 +0200 Add "save as good" to command line options commit 9c1f07d7aae3f8745c7f9854ac029b8e31af7276 Author: nephros Date: Fri May 26 10:19:18 2023 +0200 Add call to save current set as KnownGood commit 2b04ab65e21893f4eb95847d3ad007573fffe212 Author: nephros Date: Fri May 26 09:40:44 2023 +0200 Add option to load last-know-good patch list Contributes-To: #277 commit 777d43d19ab247e90b4a324238e7448630ae90a3 Author: nephros Date: Fri May 26 09:23:28 2023 +0200 if auto applying succeded, save a known good state --- .../dbus/org.SfietKonstantin.patchmanager.xml | 6 +++ src/bin/patchmanager-daemon/main.cpp | 12 +++--- .../patchmanagerobject.cpp | 43 ++++++++++++++++--- .../patchmanager-daemon/patchmanagerobject.h | 5 +++ src/qml/PatchManagerPage.qml | 6 +++ src/qml/patchmanager.cpp | 14 ++++++ src/qml/patchmanager.h | 2 + src/tools/patchmanager-tool | 12 ++++++ 8 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml b/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml index ae7e5b198..a220ac7e7 100644 --- a/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml +++ b/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml @@ -107,6 +107,12 @@ + + + + + + diff --git a/src/bin/patchmanager-daemon/main.cpp b/src/bin/patchmanager-daemon/main.cpp index 8176d7689..73a954af4 100644 --- a/src/bin/patchmanager-daemon/main.cpp +++ b/src/bin/patchmanager-daemon/main.cpp @@ -57,11 +57,13 @@ void help() { std::cout << "Patchmanager " << BUILD_VERSION << std::endl; std::cout << "Usage:" << std::endl; - std::cout << " patchmanager [--help] : Print this help text" << std::endl; - std::cout << " patchmanager -a : Enable and activate a Patch" << std::endl; - std::cout << " patchmanager -u : Deactivate and disable (unapply) a Patch" << std::endl; - std::cout << " patchmanager --unapply-all : Deactivate and disable (unapply) all Patches" << std::endl; - std::cout << " patchmanager --daemon : Start Patchmanager as daemon" << std::endl; + std::cout << " patchmanager [--help] : Print this help text" << std::endl; + std::cout << " patchmanager -a : Enable and activate a Patch" << std::endl; + std::cout << " patchmanager -u : Deactivate and disable (unapply) a Patch" << std::endl; + std::cout << " patchmanager --unapply-all : Deactivate and disable (unapply) all Patches" << std::endl; + std::cout << " patchmanager --save-as-good : Save list of enabled Patches as 'known good'" << std::endl; + std::cout << " patchmanager --load-known-good : Enable 'known good' Patches" << std::endl; + std::cout << " patchmanager --daemon : Start Patchmanager as daemon" << std::endl; } int main(int argc, char **argv) diff --git a/src/bin/patchmanager-daemon/patchmanagerobject.cpp b/src/bin/patchmanager-daemon/patchmanagerobject.cpp index 530754a5f..eebdf4f30 100644 --- a/src/bin/patchmanager-daemon/patchmanagerobject.cpp +++ b/src/bin/patchmanager-daemon/patchmanagerobject.cpp @@ -359,6 +359,21 @@ void PatchManagerObject::setAppliedPatches(const QSet &patches) putSettings(QStringLiteral("applied"), QStringList(patches.toList())); } +QSet PatchManagerObject::getLastGoodPatches() const +{ + return getSettings(QStringLiteral("lastknowngood"), QStringList()).toStringList().toSet(); +} + +void PatchManagerObject::setLastGoodPatches(const QSet &patches) +{ + putSettings(QStringLiteral("lastknowngood"), QStringList(patches.toList())); +} + +void PatchManagerObject::setKnownGood() +{ + setLastGoodPatches(getAppliedPatches()); +} + QStringList PatchManagerObject::getMangleCandidates() { if (m_mangleCandidates.empty()) { @@ -592,6 +607,10 @@ void PatchManagerObject::doPrepareCacheRoot() emit m_adaptor->autoApplyingFinished(success); } + if (success) { + setLastGoodPatches(m_appliedPatches); + } + if (!success) { setAppliedPatches(m_appliedPatches); refreshPatchList(); @@ -1113,6 +1132,10 @@ void PatchManagerObject::process() } } else if (args[1] == QStringLiteral("--unapply-all")) { method = QStringLiteral("unapplyAllPatches"); + } else if (args[1] == QStringLiteral("--save-as-good")) { + method = QStringLiteral("setKnownGood"); + } else if (args[1] == QStringLiteral("--load-known-good")) { + method = QStringLiteral("revertToLastGood"); } else { return; } @@ -1562,20 +1585,30 @@ bool PatchManagerObject::getToggleServices() const /*! Returns the internal failure state. */ bool PatchManagerObject::getFailure() const { - return m_failed; + return m_failed; } /*! Returns the internal state whether the server thread is running. */ bool PatchManagerObject::getLoaded() const { - return m_serverThread->isRunning(); + return m_serverThread->isRunning(); } /*! - Reset internal failure state and re-initialize. + Reset internal failure state and re-initialize. + + \sa loadRequest() + */ +void PatchManagerObject::revertToLastGood() +{ + QSet patches = getLastGoodPatches(); + if (!patches.empty()) { + m_appliedPatches = patches; + setAppliedPatches(patches); + refreshPatchList(); + } +} - \sa loadRequest() -*/ void PatchManagerObject::resolveFailure() { qDebug() << Q_FUNC_INFO; diff --git a/src/bin/patchmanager-daemon/patchmanagerobject.h b/src/bin/patchmanager-daemon/patchmanagerobject.h index 7f262f4d9..71ccaa1d2 100644 --- a/src/bin/patchmanager-daemon/patchmanagerobject.h +++ b/src/bin/patchmanager-daemon/patchmanagerobject.h @@ -129,6 +129,7 @@ public slots: bool getFailure() const; bool getLoaded() const; void resolveFailure(); + void revertToLastGood(); void loadRequest(bool apply); void lipstickChanged(const QString &state); @@ -216,6 +217,10 @@ private slots: QSet getAppliedPatches() const; void setAppliedPatches(const QSet &patches); + QSet getLastGoodPatches() const; + void setLastGoodPatches(const QSet &patches); + void setKnownGood(); + void getVersion(); void lateInitialize(); diff --git a/src/qml/PatchManagerPage.qml b/src/qml/PatchManagerPage.qml index b0ed4ae69..25826184e 100644 --- a/src/qml/PatchManagerPage.qml +++ b/src/qml/PatchManagerPage.qml @@ -238,6 +238,12 @@ Page { onClicked: pageStack.push(Qt.resolvedUrl("RestartServicesDialog.qml")) } + MenuItem { + text: qsTranslate("", "Load Pre-Failure List") + visible: PatchManager.failure + onClicked: menuRemorse.execute( text, function() { PatchManager.call(PatchManager.revertToLastGood()) } ) + } + MenuItem { text: qsTranslate("", "Resolve failure") visible: PatchManager.failure diff --git a/src/qml/patchmanager.cpp b/src/qml/patchmanager.cpp index e34dea1f3..fe6ca0162 100644 --- a/src/qml/patchmanager.cpp +++ b/src/qml/patchmanager.cpp @@ -815,6 +815,20 @@ void PatchManager::onLoadedChanged(bool loaded) } /*! Calls the \e resolveFailure method on D-Bus */ +void PatchManager::revertToLastGood() +{ + qDebug() << Q_FUNC_INFO; + + m_interface->revertToLastGood(); +} + +void PatchManager::setKnownGood() +{ + qDebug() << Q_FUNC_INFO; + + m_interface->setKnownGood(); +} + void PatchManager::resolveFailure() { qDebug() << Q_FUNC_INFO; diff --git a/src/qml/patchmanager.h b/src/qml/patchmanager.h index e980a67dc..052197781 100644 --- a/src/qml/patchmanager.h +++ b/src/qml/patchmanager.h @@ -182,6 +182,8 @@ public slots: void onFailureChanged(bool failed); void onLoadedChanged(bool loaded); + void setKnownGood(); + void revertToLastGood(); void resolveFailure(); signals: diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index 35c1236f1..40113862d 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -23,6 +23,8 @@ function usage() { printf "\t-A | --activate-all\t\tActivate / apply all Patches formerly marked as active.\n" printf "\t-d | --deactivate\t\tDeactivate / unapply Patches from list or file (via -f).\n" printf "\t-D | --deactivate-all\t\tDeactivate / unapply all Patches.\n" + printf "\t-S | --save-as-good\t\tSave list of enabled Patches as 'known good'\n" + printf "\t-G | --load-known-good\t\tEnable 'known good' Patches\n" printf "\t-f | --file \t\tUse for the list of Patches.\n" printf "\t-e | --export\t\t\tExport list of Patches marked as active either to STDout or (via -f) to a file.\n" printf "\t-h | --help\t\t\tPrint this help.\n" @@ -93,6 +95,16 @@ case "$1" in shift surplus "$*" ;; + -S|--save-as-good) + operation="--save-as-good" + shift + surplus "$*" + ;; + -G|--load-known-good) + operation="--load-known-good" + shift + surplus "$*" + ;; --reset-system) operation="--reset-system" shift