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
This commit is contained in:
Dirk-Jan C. Binnema
2025-11-25 21:25:21 +02:00
committed by Seth Ladygo
parent 9f69055ef9
commit 410ff46881
5 changed files with 48 additions and 52 deletions

View File

@ -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());
}
}