[shellprocess] Apply current coding style

main
Adriaan de Groot 6 years ago
parent d363732302
commit a0430f76b7

@ -18,13 +18,13 @@
#include "ShellProcessJob.h"
#include <QProcess>
#include <QDateTime>
#include <QProcess>
#include <QThread>
#include "CalamaresVersion.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/CommandList.h"
#include "utils/Logger.h"
@ -71,16 +71,23 @@ ShellProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
if ( timeout < 1 )
{
timeout = 10;
}
if ( configurationMap.contains( "script" ) )
{
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !dontChroot, std::chrono::seconds( timeout ) );
m_commands = new CalamaresUtils::CommandList(
configurationMap.value( "script" ), !dontChroot, std::chrono::seconds( timeout ) );
if ( m_commands->isEmpty() )
{
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
}
}
else
{
cWarning() << "No script given for ShellProcessJob" << moduleInstanceKey();
}
}
CALAMARES_PLUGIN_FACTORY_DEFINITION( ShellProcessJobFactory, registerPlugin< ShellProcessJob >(); )

@ -37,13 +37,9 @@ using CommandList = CalamaresUtils::CommandList;
using std::operator""s;
ShellProcessTests::ShellProcessTests()
{
}
ShellProcessTests::ShellProcessTests() {}
ShellProcessTests::~ShellProcessTests()
{
}
ShellProcessTests::~ShellProcessTests() {}
void
ShellProcessTests::initTestCase()
@ -66,8 +62,7 @@ ShellProcessTests::testProcessListSampleConfig()
}
}
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 3 );
@ -75,7 +70,8 @@ ShellProcessTests::testProcessListSampleConfig()
QCOMPARE( cl.at( 2 ).timeout(), 3600s ); // slowloris
}
void ShellProcessTests::testProcessListFromList()
void
ShellProcessTests::testProcessListFromList()
{
YAML::Node doc = YAML::Load( R"(---
script:
@ -83,8 +79,7 @@ script:
- "ls /nonexistent"
- "/bin/false"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 3 );
@ -95,19 +90,18 @@ script:
- false
- "ls /nonexistent"
)" );
CommandList cl1(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl1.isEmpty() );
QCOMPARE( cl1.count(), 2 ); // One element ignored
}
void ShellProcessTests::testProcessListFromString()
void
ShellProcessTests::testProcessListFromString()
{
YAML::Node doc = YAML::Load( R"(---
script: "ls /tmp"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
@ -118,21 +112,20 @@ script: "ls /tmp"
doc = YAML::Load( R"(---
script: false
)" );
CommandList cl1(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( cl1.isEmpty() );
QCOMPARE( cl1.count(), 0 );
}
void ShellProcessTests::testProcessFromObject()
void
ShellProcessTests::testProcessFromObject()
{
YAML::Node doc = YAML::Load( R"(---
script:
command: "ls /tmp"
timeout: 20
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
@ -140,7 +133,8 @@ script:
QCOMPARE( cl.at( 0 ).command(), QStringLiteral( "ls /tmp" ) );
}
void ShellProcessTests::testProcessListFromObject()
void
ShellProcessTests::testProcessListFromObject()
{
YAML::Node doc = YAML::Load( R"(---
script:
@ -148,8 +142,7 @@ script:
timeout: 12
- "-/bin/false"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 2 );
QCOMPARE( cl.at( 0 ).timeout(), 12s );
@ -157,25 +150,28 @@ script:
QCOMPARE( cl.at( 1 ).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() ); // not set
}
void ShellProcessTests::testRootSubstitution()
void
ShellProcessTests::testRootSubstitution()
{
YAML::Node doc = YAML::Load( R"(---
script:
- "ls /tmp"
)" );
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" );
QVariant rootScript = CalamaresUtils::yamlMapToVariant(
YAML::Load( R"(---
QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
script:
- "ls @@ROOT@@"
)" ) ).toMap().value( "script" );
QVariant userScript = CalamaresUtils::yamlMapToVariant(
YAML::Load( R"(---
)" ) )
.toMap()
.value( "script" );
QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
script:
- mktemp -d @@ROOT@@/calatestXXXXXXXX
- "chown @@USER@@ @@ROOT@@/calatest*"
- rm -rf @@ROOT@@/calatest*
)" ) ).toMap().value( "script" );
)" ) )
.toMap()
.value( "script" );
if ( !Calamares::JobQueue::instance() )
(void)new Calamares::JobQueue( nullptr );

Loading…
Cancel
Save