🧹 tui: refactor btrfs subvolumes on ROOT

This commit is contained in:
Vladislav Nepogodin 2024-07-29 01:28:14 +04:00
parent 3b75a68cc2
commit e2537840ee
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9

View File

@ -1704,8 +1704,7 @@ auto mount_root_partition(std::vector<gucc::fs::Partition>& partitions) noexcept
/* clang-format on */ /* clang-format on */
} }
const auto& root_part = std::get<std::string>(config_data["ROOT_PART"]); const auto& root_part = std::get<std::string>(config_data["ROOT_PART"]);
const auto& part = std::get<std::string>(config_data["PARTITION"]); spdlog::info("root partition: {}", root_part);
spdlog::info("partition: {}", part);
// Reset the mountpoint variable, in case this is the second time through this menu and old state is still around // Reset the mountpoint variable, in case this is the second time through this menu and old state is still around
config_data["MOUNT"] = ""; config_data["MOUNT"] = "";
@ -1736,12 +1735,9 @@ auto mount_root_partition(std::vector<gucc::fs::Partition>& partitions) noexcept
// If the root partition is btrfs, offer to create subvolumes // If the root partition is btrfs, offer to create subvolumes
if (part_fs == "btrfs"sv) { if (part_fs == "btrfs"sv) {
// Check if there are subvolumes already on the btrfs partition // Check if there are subvolumes already on the btrfs partition
const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list '{}' 2>/dev/null"), mountpoint_info); const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list '{}' 2>/dev/null | cut -d' ' -f9"), mountpoint_info);
const auto& subvolumes_count = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | wc -l"), subvolumes)); if (!subvolumes.empty()) {
const auto& lines_count = utils::to_int(subvolumes_count); const auto& existing_subvolumes = detail::yesno_widget(fmt::format(FMT_COMPILE("\nFound subvolumes {}\n \nWould you like to mount them?\n "), subvolumes), size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75));
if (lines_count > 1) {
const auto& subvolumes_formated = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | cut -d' ' -f9"), subvolumes));
const auto& existing_subvolumes = detail::yesno_widget(fmt::format(FMT_COMPILE("\nFound subvolumes {}\n \nWould you like to mount them?\n "), subvolumes_formated), size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75));
// Pre-existing subvolumes and user wants to mount them // Pre-existing subvolumes and user wants to mount them
/* clang-format off */ /* clang-format off */
if (existing_subvolumes) { utils::mount_existing_subvols(partitions); } if (existing_subvolumes) { utils::mount_existing_subvols(partitions); }