summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/mu-maildir.cc6
-rw-r--r--lib/tests/bench-indexer.cc13
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/mu-maildir.cc b/lib/mu-maildir.cc
index 53152e5..e93566a 100644
--- a/lib/mu-maildir.cc
+++ b/lib/mu-maildir.cc
@@ -297,7 +297,11 @@ msg_move_g_file(const std::string& src, const std::string& dst)
G_GNUC_UNUSED static Mu::Result<void>
msg_move_mv_file(const std::string& src, const std::string& dst)
{
- if (auto res{run_command0({"/bin/mv", src, dst})}; !res)
+ static const auto mv_path{program_in_path("mv")};
+ if (!mv_path)
+ return Err(Error::Code::File, "failed to find 'mv'");
+
+ if (auto res{run_command0({*mv_path, src, dst})}; !res)
return Err(Error::Code::File, "error moving {}->{}; err={}", src, dst, res.error());
else
return Ok();
diff --git a/lib/tests/bench-indexer.cc b/lib/tests/bench-indexer.cc
index e57bcbd..2283be1 100644
--- a/lib/tests/bench-indexer.cc
+++ b/lib/tests/bench-indexer.cc
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2022-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
@@ -24,6 +24,8 @@
#include <fstream>
#include <utils/mu-utils.hh>
+#include <utils/mu-utils-file.hh>
+
#include <utils/mu-regex.hh>
#include <mu-store.hh>
#include "mu-maildir.hh"
@@ -438,12 +440,9 @@ setup(const TestData& tdata)
static void
tear_down()
{
- /* ugly */
- GError *err{};
- const auto cmd{mu_format("/bin/rm -rf '{}' '{}'", BENCH_MAILDIRS, BENCH_STORE)};
- if (!g_spawn_command_line_sync(cmd.c_str(), NULL, NULL, NULL, &err)) {
- mu_warning("error: {}", err ? err->message : "?");
- g_clear_error(&err);
+ for (auto&& dir : { BENCH_MAILDIRS, BENCH_STORE } ) {
+ if (const auto res = remove_directory(dir); !res)
+ mu_warning("failed to remove {}: {}", dir, res.error().what());
}
}