From add90e873b022c4d789ae7493123cda5c27cb725 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 20 Jun 2019 11:52:51 +0200 Subject: [PATCH] [libcalamares] Provide overload of runCommand() - Most of the time the working dir and stdin are not important, you just want to run a command in the host, so simplify that by providing a suitable overload. - Use that overload from the partition service (for mount and sync). --- src/libcalamares/partition/Mount.cpp | 3 +-- src/libcalamares/partition/Sync.cpp | 16 ++-------------- src/libcalamares/utils/CalamaresUtilsSystem.h | 12 ++++++++++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/libcalamares/partition/Mount.cpp b/src/libcalamares/partition/Mount.cpp index 7112751ed..c1e34b89b 100644 --- a/src/libcalamares/partition/Mount.cpp +++ b/src/libcalamares/partition/Mount.cpp @@ -69,8 +69,7 @@ mount( const QString& devicePath, const QString& mountPoint, const QString& file args << "-o" << options; } - auto r = CalamaresUtils::System::instance()->runCommand( - CalamaresUtils::System::RunLocation::RunInHost, args, QString(), QString(), 10 ); + auto r = CalamaresUtils::System::instance()->runCommand( args, 10 ); sync(); return r.getExitCode(); } diff --git a/src/libcalamares/partition/Sync.cpp b/src/libcalamares/partition/Sync.cpp index 97acdc106..9c46fed24 100644 --- a/src/libcalamares/partition/Sync.cpp +++ b/src/libcalamares/partition/Sync.cpp @@ -23,14 +23,7 @@ void CalamaresUtils::Partition::sync() { - auto* s = CalamaresUtils::System::instance(); - - auto r = s->runCommand( CalamaresUtils::System::RunLocation::RunInHost, - { "/sbin/udevadm", "settle" }, - QString(), - QString(), - 10 // timeout seconds - ); + auto r = CalamaresUtils::System::runCommand( { "/sbin/udevadm", "settle" }, 10 ); if ( r.getExitCode() != 0 ) { @@ -38,10 +31,5 @@ void CalamaresUtils::Partition::sync() r.explainProcess( "udevadm", 10 ); } - s->runCommand( CalamaresUtils::System::RunLocation::RunInHost, - { "/bin/sync" }, - QString(), - QString(), - 10 // timeout seconds - ); + CalamaresUtils::System::runCommand( { "/bin/sync" }, 10 ); } diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 8f25e1ed8..2355f3455 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -123,6 +123,18 @@ public: const QString& stdInput = QString(), int timeoutSec = 0 ); + /** @brief Convenience wrapper for runCommand() + * + * Runs the given command-line @p args in the host in the current direcory + * with no input, and the given @p timeoutSec for completion. + */ + static inline ProcessResult runCommand( + const QStringList& args, + int timeoutSec ) + { + return runCommand( RunLocation::RunInHost, args, QString(), QString(), timeoutSec ); + } + /** @brief Convenience wrapper for runCommand(). * Runs the command in the location specified through the boolean * doChroot(), which is what you usually want for running commands