diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2026-03-17 08:59:29 +0200 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2026-03-17 08:59:29 +0200 |
| commit | 1ce6e76014449141f75c5d0ad94f1de638ee7460 (patch) | |
| tree | 948a6e769cb779488a6ae31f62de42d2fb8dd9da | |
| parent | a3fdc461741479cb0ad9adf7c2332e8d8f40323e (diff) | |
mu-utils-file: use std::filesystem::remove_all
Instead of the hacky "rm -rf"
| -rw-r--r-- | lib/utils/mu-utils-file.cc | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/utils/mu-utils-file.cc b/lib/utils/mu-utils-file.cc index 3da9751..ff3a7c9 100644 --- a/lib/utils/mu-utils-file.cc +++ b/lib/utils/mu-utils-file.cc @@ -29,6 +29,8 @@ #include <gio/gio.h> #include <gio/gunixinputstream.h> +#include <filesystem> + #ifdef HAVE_WORDEXP_H #include <wordexp.h> #endif /*HAVE_WORDEXP_H*/ @@ -124,22 +126,13 @@ Mu::remove_directory(const std::string& path) if (!check_dir(path, false, true)) return Err(Error::Code::File, "not a writable directory: {}", path); - // ugly: g_spawn wants gchar** - std::array<char*, 4> argv = { g_find_program_in_path("rm"), - g_strdup("-r"), g_strdup(path.c_str()), {}}; - if (!argv[0]) { - std::for_each(argv.begin(), argv.end(), g_free); - return Err(Error::Code::File, "cannot find 'rm' in path"); - } - - GError *err{}; - int status{}; - const auto res = g_spawn_sync({}, argv.data(), {}, {}, {}, {}, {}, {}, &status, &err); - std::for_each(argv.begin(), argv.end(), g_free); - if (!res) - return Err(Error::Code::File, &err, "failed to remove {}; exit-code={}", path, status); + std::error_code err{}; + const auto n{std::filesystem::remove_all(path, err)}; + if (err) + return Err(Error::Code::File, "failed to remove {}; exit-code={}", + path, err.value()); - mu_debug("removed directory '{}'", path); + mu_debug("removed directory '{}' ({})", path, n); return Ok(); } |
