From 2da430fa366c7a57d058504013d4405aad0a86c6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Jan 2018 21:25:18 +0100 Subject: [PATCH] [libcalamares] Allow CommandLine to have unset timeout - Introduce enum for the appropriate constant - If the timeout isn't set, then defer to the timeout set on the commandlist when running the commands. --- src/libcalamares/utils/CommandList.cpp | 17 +++++++++-------- src/libcalamares/utils/CommandList.h | 6 ++++-- src/modules/shellprocess/Tests.cpp | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libcalamares/utils/CommandList.cpp b/src/libcalamares/utils/CommandList.cpp index 64b88a387..eb73c798e 100644 --- a/src/libcalamares/utils/CommandList.cpp +++ b/src/libcalamares/utils/CommandList.cpp @@ -33,7 +33,7 @@ namespace CalamaresUtils static CommandLine get_variant_object( const QVariantMap& m ) { QString command = CalamaresUtils::getString( m, "command" ); - int timeout = CalamaresUtils::getInteger( m, "timeout", -1 ); + int timeout = CalamaresUtils::getInteger( m, "timeout", CommandLine::TimeoutNotSet ); if ( !command.isEmpty() ) return CommandLine( command, timeout ); @@ -41,14 +41,14 @@ static CommandLine get_variant_object( const QVariantMap& m ) return CommandLine(); } -static CommandList_t get_variant_stringlist( const QVariantList& l, int timeout ) +static CommandList_t get_variant_stringlist( const QVariantList& l ) { CommandList_t retl; unsigned int c = 0; for ( const auto& v : l ) { if ( v.type() == QVariant::String ) - retl.append( CommandLine( v.toString(), timeout ) ); + retl.append( CommandLine( v.toString(), CommandLine::TimeoutNotSet ) ); else if ( v.type() == QVariant::Map ) { auto c( get_variant_object( v.toMap() ) ); @@ -76,7 +76,7 @@ CommandList::CommandList::CommandList( const QVariant& v, bool doChroot, int tim { const auto v_list = v.toList(); if ( v_list.count() ) - append( get_variant_stringlist( v_list, m_timeout ) ); + append( get_variant_stringlist( v_list ) ); else cDebug() << "WARNING: Empty CommandList"; } @@ -118,26 +118,27 @@ Calamares::JobResult CommandList::run( const QObject* parent ) for ( CommandList::const_iterator i = cbegin(); i != cend(); ++i ) { QString processed_cmd = i->command(); - processed_cmd.replace( "@@ROOT@@", root ); // FIXME? + processed_cmd.replace( "@@ROOT@@", root ); bool suppress_result = false; if ( processed_cmd.startsWith( '-' ) ) { suppress_result = true; - processed_cmd.remove( 0, 1 ); // Drop the - // FIXME? + processed_cmd.remove( 0, 1 ); // Drop the - } QStringList shell_cmd { "/bin/sh", "-c" }; shell_cmd << processed_cmd; + int timeout = i->timeout() >= 0 ? i->timeout() : m_timeout; ProcessResult r = System::runCommand( - location, shell_cmd, QString(), QString(), i->timeout() ); + location, shell_cmd, QString(), QString(), timeout ); if ( r.getExitCode() != 0 ) { if ( suppress_result ) cDebug() << "Error code" << r.getExitCode() << "ignored by CommandList configuration."; else - return r.explainProcess( parent, processed_cmd, 10 ); + return r.explainProcess( parent, processed_cmd, timeout ); } } diff --git a/src/libcalamares/utils/CommandList.h b/src/libcalamares/utils/CommandList.h index 58d2e2721..4ed7616eb 100644 --- a/src/libcalamares/utils/CommandList.h +++ b/src/libcalamares/utils/CommandList.h @@ -33,14 +33,16 @@ namespace CalamaresUtils */ struct CommandLine : public QPair< QString, int > { + enum { TimeoutNotSet = -1 }; + /// An invalid command line CommandLine() - : QPair< QString, int >( QString(), -1 ) + : QPair< QString, int >( QString(), TimeoutNotSet ) { } CommandLine( const QString& s ) - : QPair< QString, int >( s, 10 ) + : QPair< QString, int >( s, TimeoutNotSet ) { } diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index 9792f4e7c..c406fde17 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -145,5 +145,5 @@ script: QCOMPARE( cl.count(), 2 ); QCOMPARE( cl.at(0).timeout(), 12 ); QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) ); - QCOMPARE( cl.at(1).timeout(), 10 ); // default + QCOMPARE( cl.at(1).timeout(), -1 ); // not set }