[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.
This commit is contained in:
parent
c641f5dec6
commit
2da430fa36
@ -33,7 +33,7 @@ namespace CalamaresUtils
|
|||||||
static CommandLine get_variant_object( const QVariantMap& m )
|
static CommandLine get_variant_object( const QVariantMap& m )
|
||||||
{
|
{
|
||||||
QString command = CalamaresUtils::getString( m, "command" );
|
QString command = CalamaresUtils::getString( m, "command" );
|
||||||
int timeout = CalamaresUtils::getInteger( m, "timeout", -1 );
|
int timeout = CalamaresUtils::getInteger( m, "timeout", CommandLine::TimeoutNotSet );
|
||||||
|
|
||||||
if ( !command.isEmpty() )
|
if ( !command.isEmpty() )
|
||||||
return CommandLine( command, timeout );
|
return CommandLine( command, timeout );
|
||||||
@ -41,14 +41,14 @@ static CommandLine get_variant_object( const QVariantMap& m )
|
|||||||
return CommandLine();
|
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;
|
CommandList_t retl;
|
||||||
unsigned int c = 0;
|
unsigned int c = 0;
|
||||||
for ( const auto& v : l )
|
for ( const auto& v : l )
|
||||||
{
|
{
|
||||||
if ( v.type() == QVariant::String )
|
if ( v.type() == QVariant::String )
|
||||||
retl.append( CommandLine( v.toString(), timeout ) );
|
retl.append( CommandLine( v.toString(), CommandLine::TimeoutNotSet ) );
|
||||||
else if ( v.type() == QVariant::Map )
|
else if ( v.type() == QVariant::Map )
|
||||||
{
|
{
|
||||||
auto c( get_variant_object( v.toMap() ) );
|
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();
|
const auto v_list = v.toList();
|
||||||
if ( v_list.count() )
|
if ( v_list.count() )
|
||||||
append( get_variant_stringlist( v_list, m_timeout ) );
|
append( get_variant_stringlist( v_list ) );
|
||||||
else
|
else
|
||||||
cDebug() << "WARNING: Empty CommandList";
|
cDebug() << "WARNING: Empty CommandList";
|
||||||
}
|
}
|
||||||
@ -118,26 +118,27 @@ Calamares::JobResult CommandList::run( const QObject* parent )
|
|||||||
for ( CommandList::const_iterator i = cbegin(); i != cend(); ++i )
|
for ( CommandList::const_iterator i = cbegin(); i != cend(); ++i )
|
||||||
{
|
{
|
||||||
QString processed_cmd = i->command();
|
QString processed_cmd = i->command();
|
||||||
processed_cmd.replace( "@@ROOT@@", root ); // FIXME?
|
processed_cmd.replace( "@@ROOT@@", root );
|
||||||
bool suppress_result = false;
|
bool suppress_result = false;
|
||||||
if ( processed_cmd.startsWith( '-' ) )
|
if ( processed_cmd.startsWith( '-' ) )
|
||||||
{
|
{
|
||||||
suppress_result = true;
|
suppress_result = true;
|
||||||
processed_cmd.remove( 0, 1 ); // Drop the - // FIXME?
|
processed_cmd.remove( 0, 1 ); // Drop the -
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList shell_cmd { "/bin/sh", "-c" };
|
QStringList shell_cmd { "/bin/sh", "-c" };
|
||||||
shell_cmd << processed_cmd;
|
shell_cmd << processed_cmd;
|
||||||
|
|
||||||
|
int timeout = i->timeout() >= 0 ? i->timeout() : m_timeout;
|
||||||
ProcessResult r = System::runCommand(
|
ProcessResult r = System::runCommand(
|
||||||
location, shell_cmd, QString(), QString(), i->timeout() );
|
location, shell_cmd, QString(), QString(), timeout );
|
||||||
|
|
||||||
if ( r.getExitCode() != 0 )
|
if ( r.getExitCode() != 0 )
|
||||||
{
|
{
|
||||||
if ( suppress_result )
|
if ( suppress_result )
|
||||||
cDebug() << "Error code" << r.getExitCode() << "ignored by CommandList configuration.";
|
cDebug() << "Error code" << r.getExitCode() << "ignored by CommandList configuration.";
|
||||||
else
|
else
|
||||||
return r.explainProcess( parent, processed_cmd, 10 );
|
return r.explainProcess( parent, processed_cmd, timeout );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +33,16 @@ namespace CalamaresUtils
|
|||||||
*/
|
*/
|
||||||
struct CommandLine : public QPair< QString, int >
|
struct CommandLine : public QPair< QString, int >
|
||||||
{
|
{
|
||||||
|
enum { TimeoutNotSet = -1 };
|
||||||
|
|
||||||
/// An invalid command line
|
/// An invalid command line
|
||||||
CommandLine()
|
CommandLine()
|
||||||
: QPair< QString, int >( QString(), -1 )
|
: QPair< QString, int >( QString(), TimeoutNotSet )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLine( const QString& s )
|
CommandLine( const QString& s )
|
||||||
: QPair< QString, int >( s, 10 )
|
: QPair< QString, int >( s, TimeoutNotSet )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,5 +145,5 @@ script:
|
|||||||
QCOMPARE( cl.count(), 2 );
|
QCOMPARE( cl.count(), 2 );
|
||||||
QCOMPARE( cl.at(0).timeout(), 12 );
|
QCOMPARE( cl.at(0).timeout(), 12 );
|
||||||
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
|
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
|
||||||
QCOMPARE( cl.at(1).timeout(), 10 ); // default
|
QCOMPARE( cl.at(1).timeout(), -1 ); // not set
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user