👷 gucc: add exec_checked to io_utils

This commit is contained in:
Vladislav Nepogodin 2024-07-13 17:31:14 +04:00
parent ccc4f6c459
commit 1492d40efe
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
2 changed files with 6 additions and 1 deletions

View File

@ -10,6 +10,7 @@ namespace gucc::utils {
auto safe_getenv(const char* env_name) noexcept -> std::string_view;
void exec(const std::vector<std::string>& vec) noexcept;
auto exec(std::string_view command, bool interactive = false) noexcept -> std::string;
auto exec_checked(std::string_view command) noexcept -> bool;
void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive = false) noexcept;
auto arch_chroot_checked(std::string_view command, std::string_view mountpoint) noexcept -> bool;

View File

@ -89,6 +89,10 @@ auto exec(std::string_view command, bool interactive) noexcept -> std::string {
return result;
}
auto exec_checked(std::string_view command) noexcept -> bool {
return utils::exec(command, true) == "0"sv;
}
void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive) noexcept {
// TODO(vnepogodin): refactor to move output into variable and print into log
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command);
@ -105,7 +109,7 @@ auto arch_chroot_checked(std::string_view command, std::string_view mountpoint)
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 1>/dev/null"), mountpoint, command);
#ifdef NDEVENV
return utils::exec(cmd_formatted, true) == "0";
return utils::exec(cmd_formatted, true) == "0"sv;
#else
spdlog::info("Running with checked arch-chroot: '{}'", cmd_formatted);
return true;