From dc7a1e43b73af5ab216df977ed518fd63f252585 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 11 Dec 2021 16:19:28 +0100 Subject: [PATCH] [partition] Add helper for running a KPMCore operation Most *partition* module jobs run an operation and turn that into a JobResult -- ok if it succeeds, and with the report text otherwise. Factor it out into a separate method that can be used as shorthand. --- src/modules/partition/core/KPMHelpers.cpp | 15 +++++++++++++++ src/modules/partition/core/KPMHelpers.h | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index ed105e28b..46efeb392 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -127,4 +127,19 @@ clonePartition( Device* device, Partition* partition ) partition->activeFlags() ); } +Calamares::JobResult +execute( Operation& operation, const QString& failureMessage ) +{ + operation.setStatus( Operation::StatusRunning ); + + Report report( nullptr ); + if ( operation.execute( report ) ) + { + return Calamares::JobResult::ok(); + } + + return Calamares::JobResult::error( failureMessage, report.toText() ); +} + + } // namespace KPMHelpers diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 89a019f6c..1d40dd363 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -11,11 +11,13 @@ #ifndef KPMHELPERS_H #define KPMHELPERS_H -// KPMcore +#include "Job.h" + #include #include +#include +#include -// Qt #include #include @@ -72,6 +74,14 @@ Partition* createNewEncryptedPartition( PartitionNode* parent, Partition* clonePartition( Device* device, Partition* partition ); +/** @brief Return a result for an @p operation + * + * Executes the operation, and if successful, returns a success result. + * Otherwise returns an error using @p failureMessage as the primary part + * of the error, and details obtained from the operation. + */ +Calamares::JobResult execute( Operation& operation, const QString& failureMessage ); + } // namespace KPMHelpers #endif /* KPMHELPERS_H */