diff --git a/gucc/include/gucc/io_utils.hpp b/gucc/include/gucc/io_utils.hpp index fc59891..31cb912 100644 --- a/gucc/include/gucc/io_utils.hpp +++ b/gucc/include/gucc/io_utils.hpp @@ -10,6 +10,7 @@ namespace gucc::utils { auto safe_getenv(const char* env_name) noexcept -> std::string_view; void exec(const std::vector& 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; diff --git a/gucc/src/io_utils.cpp b/gucc/src/io_utils.cpp index 2e5c2d2..b3da785 100644 --- a/gucc/src/io_utils.cpp +++ b/gucc/src/io_utils.cpp @@ -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;