1010// import gucc
1111#include " gucc/block_devices.hpp"
1212#include " gucc/btrfs.hpp"
13- #include " gucc/fs_utils.hpp"
1413#include " gucc/io_utils.hpp"
14+ #include " gucc/lvm.hpp"
1515#include " gucc/partition.hpp"
1616#include " gucc/partition_config.hpp"
1717#include " gucc/string_utils.hpp"
@@ -45,12 +45,12 @@ constexpr auto find_root_btrfs_part(auto&& parts) noexcept {
4545}
4646
4747// / Store LUKS/LVM state from a mount result into the Config singleton.
48- void store_luks_config (auto & config_data, cachyos::installer::MountPartitionResult& & mount_result) noexcept {
48+ void store_luks_config (auto & config_data, const cachyos::installer::MountPartitionResult& mount_result) noexcept {
4949 std::get<std::int32_t >(config_data[" LUKS" ]) = mount_result.is_luks ;
5050 std::get<std::int32_t >(config_data[" LVM" ]) = mount_result.is_lvm ;
51- std::get<std::string>(config_data[" LUKS_NAME" ]) = std::move ( mount_result.luks_name ) ;
52- std::get<std::string>(config_data[" LUKS_DEV" ]) = std::move ( mount_result.luks_dev ) ;
53- std::get<std::string>(config_data[" LUKS_UUID" ]) = std::move ( mount_result.luks_uuid ) ;
51+ std::get<std::string>(config_data[" LUKS_NAME" ]) = mount_result.luks_name ;
52+ std::get<std::string>(config_data[" LUKS_DEV" ]) = mount_result.luks_dev ;
53+ std::get<std::string>(config_data[" LUKS_UUID" ]) = mount_result.luks_uuid ;
5454}
5555
5656} // namespace
@@ -223,17 +223,13 @@ auto mount_existing_subvols(std::vector<gucc::fs::Partition>& partitions) noexce
223223 return true ;
224224}
225225
226- std::vector<std::string> lvm_show_vg () noexcept {
227- const auto & vg_list = gucc::utils::make_multiline (gucc::utils::exec (" lvs --noheadings | awk '{print $2}' | uniq" sv));
228-
229- std::vector<std::string> res{};
230- res.reserve (vg_list.size ());
231- for (const auto & vg : vg_list) {
232- const auto & temp = gucc::utils::exec (fmt::format (FMT_COMPILE (" vgdisplay {} | grep -i \" vg size\" | {}" ), vg, " awk '{print $3$4}'" sv));
233- res.push_back (temp);
234- }
235-
236- return res;
226+ auto lvm_show_vg () noexcept -> std::vector<std::pair<std::string, std::string>> {
227+ #ifdef NDEVENV
228+ return gucc::lvm::show_volume_groups ();
229+ #else
230+ spdlog::info (" [DRY-RUN] Would query volume groups" );
231+ return {};
232+ #endif
237233}
238234
239235// Automated configuration of zfs. Creates a new zpool and a default set of filesystems
@@ -502,7 +498,6 @@ auto apply_mount_selections_interactive(const MountSelections& selections) noexc
502498 // 3. Apply additional partitions
503499 const auto & mountpoint_info = std::get<std::string>(config_data[" MOUNTPOINT" ]);
504500 for (const auto & p : selections.additional ) {
505- // Format if requested
506501 if (p.format_requested ) {
507502#ifdef NDEVENV
508503 const auto & mkfs_cmd = fmt::format (FMT_COMPILE (" {} {}" ), p.mkfs_command , p.device );
@@ -516,33 +511,36 @@ auto apply_mount_selections_interactive(const MountSelections& selections) noexc
516511#endif
517512 }
518513
519- // Mount
520- if (!utils::mount_partition (p.device , mountpoint_info, p.mountpoint , p.mount_opts )) {
521- spdlog::error (" Failed to mount {} at {}" , p.device , p.mountpoint );
514+ #ifdef NDEVENV
515+ auto mount_res = cachyos::installer::mount_partition (p.device , mountpoint_info, p.mountpoint , p.mount_opts );
516+ if (!mount_res) {
517+ spdlog::error (" {}" , mount_res.error ());
522518 return false ;
523519 }
524520
525- // get mountpoint
526- const auto & part_mountpoint = fmt::format (FMT_COMPILE (" {}{}" ), mountpoint_info, p.mountpoint );
527- const auto & part_fs = gucc::fs::utils::get_mountpoint_fs (part_mountpoint);
528- auto part_struct = gucc::fs::Partition{
529- .fstype = part_fs.empty () ? p.fstype : std::string{part_fs},
521+ auto part_struct = gucc::fs::Partition{
522+ .fstype = mount_res->fstype .empty () ? p.fstype : mount_res->fstype ,
530523 .mountpoint = p.mountpoint ,
531524 .device = p.device ,
532525 .mount_opts = p.mount_opts ,
533526 };
534- part_struct.uuid_str = gucc::fs::utils::get_device_uuid (p.device );
535-
536- // get luks information about the additional partition
537- const auto & luks_name = std::get<std::string>(config_data[" LUKS_NAME" ]);
538- const auto & luks_uuid = std::get<std::string>(config_data[" LUKS_UUID" ]);
539- if (!luks_name.empty ()) {
540- part_struct.luks_mapper_name = luks_name;
527+ part_struct.uuid_str = mount_res->uuid ;
528+ if (mount_res->is_luks && !mount_res->luks_name .empty ()) {
529+ part_struct.luks_mapper_name = mount_res->luks_name ;
541530 }
542- if (! luks_uuid.empty ()) {
543- part_struct.luks_uuid = luks_uuid;
531+ if (mount_res-> is_luks && !mount_res-> luks_uuid .empty ()) {
532+ part_struct.luks_uuid = mount_res-> luks_uuid ;
544533 }
545-
534+ store_luks_config (config_data, *mount_res);
535+ #else
536+ spdlog::info (" [DRY-RUN] Would mount {} at {}{}" , p.device , mountpoint_info, p.mountpoint );
537+ auto part_struct = gucc::fs::Partition{
538+ .fstype = p.fstype ,
539+ .mountpoint = p.mountpoint ,
540+ .device = p.device ,
541+ .mount_opts = p.mount_opts ,
542+ };
543+ #endif
546544 utils::dump_partition_to_log (part_struct);
547545 // insert partition
548546 partitions.emplace_back (std::move (part_struct));
@@ -556,7 +554,7 @@ auto apply_mount_selections_interactive(const MountSelections& selections) noexc
556554 const auto & boot_devices = gucc::disk::list_block_devices ();
557555 if (boot_devices) {
558556 const auto & boot_dev = gucc::disk::find_device_by_name (*boot_devices, p.device );
559- if (boot_dev && boot_dev->type == " lvm" ) {
557+ if (boot_dev && boot_dev->type == " lvm" sv ) {
560558 config_data[" LVM_SEP_BOOT" ] = 2 ;
561559 }
562560 }
0 commit comments