mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 05:52:23 +08:00
👷 gucc: add helper function to find block device by parent
Some checks are pending
Build / Build with CMake (push) Waiting to run
Build / Build with CMake (DEVENV OFF) (push) Waiting to run
Build / Build with Meson (push) Waiting to run
Build / Build with Meson (DEVENV OFF) (push) Waiting to run
Checks / cpp-linter (push) Waiting to run
Checks / Check C++ style (push) Waiting to run
Some checks are pending
Build / Build with CMake (push) Waiting to run
Build / Build with CMake (DEVENV OFF) (push) Waiting to run
Build / Build with Meson (push) Waiting to run
Build / Build with Meson (DEVENV OFF) (push) Waiting to run
Checks / cpp-linter (push) Waiting to run
Checks / Check C++ style (push) Waiting to run
This commit is contained in:
parent
a3ece6c01d
commit
36007299a6
@ -46,6 +46,12 @@ auto list_block_devices() -> std::optional<std::vector<BlockDevice>>;
|
||||
/// @return An optional BlockDevice object if found, std::nullopt otherwise.
|
||||
auto find_device_by_name(const std::vector<BlockDevice>& devices, std::string_view device_name) -> std::optional<BlockDevice>;
|
||||
|
||||
/// @brief Finds a block device by matching its parent kernel name (pkname).
|
||||
/// @param devices A vector of BlockDevice objects.
|
||||
/// @param pkname A string view representing the parent kernel name to search for.
|
||||
/// @return An optional BlockDevice object if found, std::nullopt otherwise.
|
||||
auto find_device_by_pkname(const std::vector<BlockDevice>& devices, std::string_view pkname) -> std::optional<BlockDevice>;
|
||||
|
||||
} // namespace gucc::disk
|
||||
|
||||
#endif // BLOCK_DEVICES_HPP
|
||||
|
@ -88,6 +88,19 @@ auto find_device_by_name(const std::vector<BlockDevice>& devices, std::string_vi
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto find_device_by_pkname(const std::vector<BlockDevice>& devices, std::string_view pkname) -> std::optional<BlockDevice> {
|
||||
auto it = std::ranges::find_if(devices, [pkname](auto&& dev) {
|
||||
if (dev.pkname) {
|
||||
return *dev.pkname == pkname;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (it != std::ranges::end(devices)) {
|
||||
return std::make_optional<BlockDevice>(std::move(*it));
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto list_block_devices() -> std::optional<std::vector<BlockDevice>> {
|
||||
const auto& lsblk_output = utils::exec(R"(lsblk -f -o NAME,TYPE,FSTYPE,UUID,PARTUUID,PKNAME,LABEL,SIZE,MOUNTPOINT,MODEL -b -p -a -J -Q "type=='part' || type=='crypt' && fstype")");
|
||||
if (lsblk_output.empty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user