diff --git a/lib/utils/mu-utils-file.cc b/lib/utils/mu-utils-file.cc index 4a0ba25b..e121594a 100644 --- a/lib/utils/mu-utils-file.cc +++ b/lib/utils/mu-utils-file.cc @@ -162,7 +162,7 @@ Mu::runtime_path(Mu::RuntimePath path, const std::string& muhome) throw std::logic_error("unknown path"); } } - +/* LCOV_EXCL_START*/ static gpointer cancel_wait(gpointer data) { @@ -210,7 +210,7 @@ Mu::g_cancellable_new_with_timeout(guint timeout) return cancel; } - +/* LCOV_EXCL_STOP*/ Result Mu::read_from_stdin() @@ -286,6 +286,18 @@ Mu::run_command(std::initializer_list args, bool try_setsid) to_string_gchar(std::move(std_err/*consumed*/))}); } +Result +Mu::run_command0(std::initializer_list args, bool try_setsid) +{ + if (auto&& res{run_command(args, try_setsid)}; !res) + return res; + else if (res->exit_code != 0) + return Err(Error::Code::File, "command ran with non-zero exit code"); + else + return Ok(std::move(*res)); +} + + Mu::Option Mu::program_in_path(const std::string& name) { diff --git a/lib/utils/mu-utils-file.hh b/lib/utils/mu-utils-file.hh index 1245865e..503de33c 100644 --- a/lib/utils/mu-utils-file.hh +++ b/lib/utils/mu-utils-file.hh @@ -227,14 +227,14 @@ Result make_temp_dir(); Result remove_directory(const std::string& path); /** - * Run some system command + * Run some system command. * * @param args a list of commmand line arguments (like argv) * @param try_setsid whether to try setsid(2) (see its manpage for details) if this * system supports it. * - * @return Ok(exit code) or an error. Note that exit-code != 0 is _not_ - * considered an error from the perspective of this function. + * @return Ok(exit code) or an error. Note that exit-code != 0 is _not_ considered an error from the + * perspective of run_command, but is for run_command0 */ struct CommandOutput { int exit_code; @@ -243,6 +243,8 @@ struct CommandOutput { }; Result run_command(std::initializer_list args, bool try_setsid=false); +Result run_command0(std::initializer_list args, + bool try_setsid=false); /** * Try to 'play' (ie., open with it's associated program) a file. On MacOS, the