Skip to content

Commit

Permalink
[unpackfsc] Copy 'condition' idea from unpackfs
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaandegroot committed Nov 5, 2024
1 parent 7bec3f6 commit 0186985
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 5 deletions.
70 changes: 66 additions & 4 deletions modules/unpackfsc/UnpackFSCJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "TarballRunner.h"
#include "UnsquashRunner.h"

#include <GlobalStorage.h>
#include <utils/Logger.h>
#include <utils/NamedEnum.h>
#include <utils/RAII.h>
Expand Down Expand Up @@ -50,7 +51,7 @@ UnpackFSCJob::UnpackFSCJob( QObject* parent )
{
}

UnpackFSCJob::~UnpackFSCJob() { }
UnpackFSCJob::~UnpackFSCJob() {}

QString
UnpackFSCJob::prettyName() const
Expand All @@ -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 )
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions modules/unpackfsc/UnpackFSCJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
11 changes: 11 additions & 0 deletions modules/unpackfsc/unpackfsc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion modules/unpackfsc/unpackfsc.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

0 comments on commit 0186985

Please sign in to comment.