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

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