summaryrefslogtreecommitdiff
path: root/mu
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-11-25 21:25:21 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-11-25 21:28:02 +0200
commitfc4d5b01a703e8c8cc390cfea135f08d3b45ccab (patch)
tree79f813eaad8c8c6318e6f4b35577f8d2afcb9e9e /mu
parentfb806392c35d7a63258c91badef56de55b0daafe (diff)
improve invoking external commands
- don't make assumptions on where programs live (i.e., /bin/sh, /bin/rm, /bin/mv) are not universal - dont invoke shell when unnecessary - improve error-handling
Diffstat (limited to 'mu')
-rw-r--r--mu/mu-options.cc7
-rw-r--r--mu/tests/test-mu-query.cc20
2 files changed, 16 insertions, 11 deletions
diff --git a/mu/mu-options.cc b/mu/mu-options.cc
index 58e1385..ac9d885 100644
--- a/mu/mu-options.cc
+++ b/mu/mu-options.cc
@@ -829,13 +829,14 @@ add_scripts(CLI::App& app, Options& opts)
static Result<Options>
show_manpage(Options& opts, const std::string& name)
{
- char *path = g_find_program_in_path("man");
- if (!path)
+ const auto manprog{program_in_path("man")};
+ if (!manprog)
return Err(Error::Code::Command,
"cannot find 'man' program");
GError* err{};
- auto cmd{to_string_gchar(std::move(path)) + " " + name};
+ const auto cmd{mu_format("{} {}", *manprog, name)};
+ // run_command0 doesn't work here.
auto res = g_spawn_command_line_sync(cmd.c_str(), {}, {}, {}, &err);
if (!res)
return Err(Error::Code::Command, &err,
diff --git a/mu/tests/test-mu-query.cc b/mu/tests/test-mu-query.cc
index 09c0cde..5f04f86 100644
--- a/mu/tests/test-mu-query.cc
+++ b/mu/tests/test-mu-query.cc
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2008-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2008-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@@ -47,16 +47,20 @@ make_database(const std::string& dbdir, const std::string& testdir)
{
/* use the env var rather than `--muhome` */
g_setenv("MUHOME", dbdir.c_str(), 1);
- const auto cmdline{mu_format(
- "/bin/sh -c '"
- "{} --quiet init --maildir={} ; "
- "{} --quiet index'",
- MU_PROGRAM, testdir, MU_PROGRAM)};
+
+ {
+ const auto res = run_command0({MU_PROGRAM, "--quiet", "init", "--maildir", testdir});
+ assert_valid_result(res);
+ }
+
+ {
+ const auto res = run_command0({MU_PROGRAM, "--quiet", "index"});
+ assert_valid_result(res);
+ }
if (g_test_verbose())
- mu_printerrln("\n{}", cmdline);
+ mu_info("\nindexed {} @ {}", testdir, dbdir);
- g_assert(g_spawn_command_line_sync(cmdline.c_str(), NULL, NULL, NULL, NULL));
auto xpath = join_paths(dbdir, "xapian");
/* ensure MUHOME worked */
g_assert_cmpuint(::access(xpath.c_str(), F_OK), ==, 0);