From 0186985726ad5bdc27a5cb32584b0df71fc0f390 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 5 Nov 2024 15:16:04 +0100 Subject: [PATCH] [unpackfsc] Copy 'condition' idea from unpackfs --- modules/unpackfsc/UnpackFSCJob.cpp | 70 +++++++++++++++++++++++-- modules/unpackfsc/UnpackFSCJob.h | 1 + modules/unpackfsc/unpackfsc.conf | 11 ++++ modules/unpackfsc/unpackfsc.schema.yaml | 5 +- 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/modules/unpackfsc/UnpackFSCJob.cpp b/modules/unpackfsc/UnpackFSCJob.cpp index 832abff..7b453f6 100644 --- a/modules/unpackfsc/UnpackFSCJob.cpp +++ b/modules/unpackfsc/UnpackFSCJob.cpp @@ -13,6 +13,7 @@ #include "TarballRunner.h" #include "UnsquashRunner.h" +#include #include #include #include @@ -50,7 +51,7 @@ UnpackFSCJob::UnpackFSCJob( QObject* parent ) { } -UnpackFSCJob::~UnpackFSCJob() { } +UnpackFSCJob::~UnpackFSCJob() {} QString UnpackFSCJob::prettyName() const @@ -63,9 +64,43 @@ UnpackFSCJob::prettyStatusMessage() const { return m_progressMessage; } + +static bool +checkCondition( const QString& condition ) +{ + if ( condition.isEmpty() ) + { + return true; + } + + GlobalStorage* gs = JobQueue::instance()->globalStorage(); + + bool ok = false; + const auto v = Calamares::lookup( gs, m_condition, ok ); + if ( !ok ) + { + cWarning() << "Item has condition '" << m_condition << "' which is not set at all (assuming 'true')."; + return true; + } + + if ( !v.canConvert< bool >() ) + { + cWarning() << "Item has condition '" << m_condition << "' with value" << v << "(assuming 'true')."; + return true; + } + + return v.toBool(); +} + Calamares::JobResult UnpackFSCJob::exec() { + if ( !checkCondition( m_condition ) ) + { + cDebug() << "Skipping item with condition '" << m_condition << "' which is set to false."; + return Calamares::JobResult::ok(); + } + cScopedAssignment messageClearer( &m_progressMessage, QString() ); std::unique_ptr< Runner > r; switch ( m_type ) @@ -101,8 +136,10 @@ UnpackFSCJob::exec() void UnpackFSCJob::setConfigurationMap( const QVariantMap& map ) { - QString source = Calamares::getString( map, "source" ); - QString sourceTypeName = Calamares::getString( map, "sourcefs" ); + m_type = Type::None; + + const QString source = Calamares::getString( map, "source" ); + const QString sourceTypeName = Calamares::getString( map, "sourcefs" ); if ( source.isEmpty() || sourceTypeName.isEmpty() ) { cWarning() << "Skipping item with bad source data:" << map; @@ -115,12 +152,37 @@ UnpackFSCJob::setConfigurationMap( const QVariantMap& map ) cWarning() << "Skipping item with source type None"; return; } - QString destination = Calamares::getString( map, "destination" ); + const QString destination = Calamares::getString( map, "destination" ); if ( destination.isEmpty() ) { cWarning() << "Skipping item with empty destination"; return; } + const auto conditionKey = QStringLiteral( "condition" ); + if ( map.contains( conditionKey ) ) + { + const auto value = map[ conditionKey ]; + if ( Calamares::typeOf( value ) == Calamares::BoolVariantType ) + { + if ( !value.toBool() ) + { + cDebug() << "Skipping item with condition set to false."; + // Leave type set to None, which will be skipped later + return; + } + // Else the condition is true, and we're fine leaving the string empty because that defaults to true + } + else + { + const auto variable = value.toString(); + if ( variable.isEmpty() ) + { + cDebug() << "Skipping item with condition '" << value << "' that is empty (use 'true' instead)."; + return; + } + m_condition = variable; + } + } m_source = source; m_destination = destination; diff --git a/modules/unpackfsc/UnpackFSCJob.h b/modules/unpackfsc/UnpackFSCJob.h index af0a38a..cc0a915 100644 --- a/modules/unpackfsc/UnpackFSCJob.h +++ b/modules/unpackfsc/UnpackFSCJob.h @@ -43,6 +43,7 @@ class PLUGINDLLEXPORT UnpackFSCJob : public Calamares::CppJob QString m_destination; Type m_type = Type::None; QString m_progressMessage; + QString m_conditionVariable; ///< May be empty to express condition "true" }; CALAMARES_PLUGIN_FACTORY_DECLARATION( UnpackFSCFactory ) diff --git a/modules/unpackfsc/unpackfsc.conf b/modules/unpackfsc/unpackfsc.conf index beebc3b..7cb4c32 100644 --- a/modules/unpackfsc/unpackfsc.conf +++ b/modules/unpackfsc/unpackfsc.conf @@ -34,6 +34,17 @@ # empty string, which effectively is / (the root) of the target # system. # +# +# There are the following **optional** keys: +# - *condition* sets a dynamic condition on unpacking the item in +# this job. This may be true or false (constant) or name a globalstorage +# value. Use '.' to separate parts of a globalstorage name if it is nested. +# Remember to quote names. +# +# A condition is used in e.g. stacked squashfses, where the user can select +# a specific install type. The default value of *condition* is true. + source: /data/rootfs.fsa sourcefs: fsarchiver destination: "/" +# condition: true diff --git a/modules/unpackfsc/unpackfsc.schema.yaml b/modules/unpackfsc/unpackfsc.schema.yaml index e329de7..14493b6 100644 --- a/modules/unpackfsc/unpackfsc.schema.yaml +++ b/modules/unpackfsc/unpackfsc.schema.yaml @@ -15,5 +15,8 @@ properties: source: { type: string } sourcefs: { type: string } destination: { type: string } - weight: { type: integer, exclusiveMinimum: 0 } + condition: + anyOf: + - type: boolean + - type: string required: [ source , sourcefs, destination ]