From 066a05a934b000a6d794ac32668249ae49e15fee Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 13 Jul 2024 17:36:26 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20gucc:=20refactor=20to=20use=20ut?= =?UTF-8?q?ils::exec=5Fchecked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/src/btrfs.cpp | 2 +- gucc/src/io_utils.cpp | 2 +- gucc/src/luks.cpp | 6 +++--- gucc/src/mount_partitions.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gucc/src/btrfs.cpp b/gucc/src/btrfs.cpp index a876ae0..0a40758 100644 --- a/gucc/src/btrfs.cpp +++ b/gucc/src/btrfs.cpp @@ -37,7 +37,7 @@ auto btrfs_create_subvol(std::string_view subvolume, std::string_view root_mount return false; } auto cmd = fmt::format(FMT_COMPILE("btrfs subvolume create {}{} 2>>/tmp/cachyos-install.log"), root_mountpoint, subvolume); - return utils::exec(cmd, true) == "0"; + return utils::exec_checked(cmd); } auto btrfs_create_subvols(const std::vector& subvols, std::string_view device, std::string_view root_mountpoint, std::string_view mount_opts) noexcept -> bool { diff --git a/gucc/src/io_utils.cpp b/gucc/src/io_utils.cpp index b3da785..d0d2ca0 100644 --- a/gucc/src/io_utils.cpp +++ b/gucc/src/io_utils.cpp @@ -109,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"sv; + return utils::exec_checked(cmd_formatted); #else spdlog::info("Running with checked arch-chroot: '{}'", cmd_formatted); return true; diff --git a/gucc/src/luks.cpp b/gucc/src/luks.cpp index b7be8f6..1394873 100644 --- a/gucc/src/luks.cpp +++ b/gucc/src/luks.cpp @@ -12,17 +12,17 @@ namespace gucc::crypto { auto luks1_open(std::string_view luks_pass, std::string_view partition, std::string_view luks_name) noexcept -> bool { auto cmd = fmt::format(FMT_COMPILE("echo \"{}\" | cryptsetup open --type luks1 {} {} &>/dev/null"), luks_pass, partition, luks_name); - return utils::exec(cmd, true) == "0"; + return utils::exec_checked(cmd); } auto luks1_format(std::string_view luks_pass, std::string_view partition, std::string_view additional_flags) noexcept -> bool { auto cmd = fmt::format(FMT_COMPILE("echo \"{}\" | cryptsetup -q {} --type luks1 luksFormat {} &>/dev/null"), luks_pass, additional_flags, partition); - return utils::exec(cmd, true) == "0"; + return utils::exec_checked(cmd); } auto luks1_add_key(std::string_view dest_file, std::string_view partition, std::string_view additional_flags) noexcept -> bool { auto cmd = fmt::format(FMT_COMPILE("cryptsetup -q {} luksAddKey {} {} &>/dev/null"), additional_flags, partition, dest_file); - return utils::exec(cmd, true) == "0"; + return utils::exec_checked(cmd); } // see https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#With_a_keyfile_embedded_in_the_initramfs diff --git a/gucc/src/mount_partitions.cpp b/gucc/src/mount_partitions.cpp index b5980d5..88d8a35 100644 --- a/gucc/src/mount_partitions.cpp +++ b/gucc/src/mount_partitions.cpp @@ -11,21 +11,21 @@ namespace gucc::mount { auto mount_partition(std::string_view partition, std::string_view mount_dir, std::string_view mount_opts) noexcept -> bool { if (!mount_opts.empty()) { - return utils::exec(fmt::format(FMT_COMPILE("mount -o {} {} {}"), mount_opts, partition, mount_dir)) == "0"; + return utils::exec_checked(fmt::format(FMT_COMPILE("mount -o {} {} {}"), mount_opts, partition, mount_dir)); } - return utils::exec(fmt::format(FMT_COMPILE("mount {} {}"), partition, mount_dir)) == "0"; + return utils::exec_checked(fmt::format(FMT_COMPILE("mount {} {}"), partition, mount_dir)); } auto query_partition(std::string_view partition, std::int32_t& is_luks, std::int32_t& is_lvm, std::string& luks_name, std::string& luks_dev, std::string& luks_uuid) noexcept -> bool { // Identify if mounted partition is type "crypt" (LUKS on LVM, or LUKS alone) - if (utils::exec(fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'crypt'"), partition), true) == "0") { + if (utils::exec_checked(fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'crypt'"), partition))) { // cryptname for bootloader configuration either way is_luks = true; luks_name = utils::exec(fmt::format(FMT_COMPILE("echo {} | sed \"s~^/dev/mapper/~~g\""), partition)); const auto& check_cryptparts = [&](auto&& cryptparts, const auto& functor) { for (const auto& cryptpart : cryptparts) { - if (utils::exec(fmt::format(FMT_COMPILE("lsblk -lno NAME {} | grep -q '{}'"), cryptpart, luks_name)) == "0") { + if (utils::exec_checked(fmt::format(FMT_COMPILE("lsblk -lno NAME {} | grep -q '{}'"), cryptpart, luks_name))) { functor(cryptpart); return true; }