From 45ade9ed50d5efd54c652d12ab5fa83899e526da Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 28 Jul 2024 19:52:06 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20gucc:=20add=20helper=20function?= =?UTF-8?q?=20to=20get=20UUID=20of=20device/part?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/include/gucc/fs_utils.hpp | 3 +++ gucc/src/fs_utils.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/gucc/include/gucc/fs_utils.hpp b/gucc/include/gucc/fs_utils.hpp index 1b1ffb7..035abfb 100644 --- a/gucc/include/gucc/fs_utils.hpp +++ b/gucc/include/gucc/fs_utils.hpp @@ -12,6 +12,9 @@ auto get_mountpoint_fs(std::string_view mountpoint) noexcept -> std::string; // Get SOURCE of mountpoint auto get_mountpoint_source(std::string_view mountpoint) noexcept -> std::string; +// Get UUID of device/partition +auto get_device_uuid(std::string_view device) noexcept -> std::string; + } // namespace gucc::fs::utils #endif // FS_UTILS_HPP diff --git a/gucc/src/fs_utils.cpp b/gucc/src/fs_utils.cpp index 5724b65..5174322 100644 --- a/gucc/src/fs_utils.cpp +++ b/gucc/src/fs_utils.cpp @@ -16,4 +16,8 @@ auto get_mountpoint_source(std::string_view mountpoint) noexcept -> std::string return gucc::utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o SOURCE \"{}\""), mountpoint)); } +auto get_device_uuid(std::string_view device) noexcept -> std::string { + return gucc::utils::exec(fmt::format(FMT_COMPILE("lsblk -o UUID '{}' | awk 'NR==2'"), device)); +} + } // namespace gucc::fs::utils