diff --git a/gucc/include/gucc/zfs.hpp b/gucc/include/gucc/zfs.hpp index f6ef94c..570d495 100644 --- a/gucc/include/gucc/zfs.hpp +++ b/gucc/include/gucc/zfs.hpp @@ -13,7 +13,7 @@ struct ZfsDataset final { }; // Creates a zfs volume -void zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept; +auto zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept -> bool; // Creates a zfs filesystem, the first parameter is the ZFS path and the second is the mount path auto zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcept -> bool; @@ -21,7 +21,7 @@ auto zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcep // Creates a zfs datasets from predefined scheme auto zfs_create_datasets(const std::vector& zdatasets) noexcept -> bool; -void zfs_destroy_dataset(std::string_view zdataset) noexcept; +auto zfs_destroy_dataset(std::string_view zdataset) noexcept -> bool; // returns a list of imported zpools auto zfs_list_pools() noexcept -> std::string; @@ -31,7 +31,8 @@ auto zfs_list_devs() noexcept -> std::string; auto zfs_list_datasets(std::string_view type = "none") noexcept -> std::string; -void zfs_set_property(std::string_view property, std::string_view dataset) noexcept; +// Sets zfs property +auto zfs_set_property(std::string_view property, std::string_view dataset) noexcept -> bool; } // namespace gucc::fs diff --git a/gucc/src/zfs.cpp b/gucc/src/zfs.cpp index 37c2390..8717a1b 100644 --- a/gucc/src/zfs.cpp +++ b/gucc/src/zfs.cpp @@ -12,11 +12,12 @@ using namespace std::string_view_literals; namespace gucc::fs { // Creates a zfs volume -void zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept { +auto zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept -> bool { #ifdef NDEVENV - utils::exec(fmt::format(FMT_COMPILE("zfs create -V {}M {} 2>>/tmp/cachyos-install.log"), zsize, zpath), true); + return utils::exec_checked(fmt::format(FMT_COMPILE("zfs create -V {}M {} 2>>/tmp/cachyos-install.log"), zsize, zpath)); #else spdlog::debug("zfs create -V {}M {}", zsize, zpath); + return true; #endif } @@ -41,11 +42,12 @@ auto zfs_create_datasets(const std::vector& zdatasets) noexcept -> b return true; } -void zfs_destroy_dataset(std::string_view zdataset) noexcept { +auto zfs_destroy_dataset(std::string_view zdataset) noexcept -> bool { #ifdef NDEVENV - utils::exec(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset), true); + return utils::exec_checked(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset)); #else spdlog::debug("zfs destroy -r {}", zdataset); + return true; #endif } @@ -87,11 +89,12 @@ auto zfs_list_datasets(std::string_view type) noexcept -> std::string { #endif } -void zfs_set_property(std::string_view property, std::string_view dataset) noexcept { +auto zfs_set_property(std::string_view property, std::string_view dataset) noexcept -> bool { #ifdef NDEVENV - utils::exec(fmt::format(FMT_COMPILE("zfs set {} {} 2>>/tmp/cachyos-install.log"), property, dataset), true); + return utils::exec_checked(fmt::format(FMT_COMPILE("zfs set {} {} 2>>/tmp/cachyos-install.log"), property, dataset)); #else spdlog::debug("zfs set {} {}", property, dataset); + return true; #endif } diff --git a/src/tui.cpp b/src/tui.cpp index cb649c4..1fd0eb6 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -1346,7 +1346,9 @@ bool zfs_new_ds(const std::string_view& zmount = "") noexcept { const auto& zfs_zpath = fmt::format(FMT_COMPILE("{}/{}"), zfs_zpool_name, zfs_dataset_name); if (zmount == "legacy"sv) { - gucc::fs::zfs_create_dataset(zfs_zpath, zmount); + if (!gucc::fs::zfs_create_dataset(zfs_zpath, zmount)) { + spdlog::error("Failed to create zfs dataset {} at mountpoint {}", zfs_zpath, zmount); + } } else if (zmount == "zvol"sv) { static constexpr auto zvol_size_menu_body = "\nEnter the size of the zvol in megabytes(MB)\n"sv; static constexpr auto zvol_size_menu_validation = "\nYou must enter a number greater than 0\n"sv; @@ -1372,7 +1374,9 @@ bool zfs_new_ds(const std::string_view& zmount = "") noexcept { if (zfs_menu_text == zvol_size_menu_body) { break; } /* clang-format on */ } - gucc::fs::zfs_create_zvol(zvol_size, zfs_zpath); + if (!gucc::fs::zfs_create_zvol(zvol_size, zfs_zpath)) { + spdlog::error("Failed to create zfs zvol {} with size {}", zfs_zpath, zvol_size); + } } else { spdlog::error("HELLO! IMPLEMENT ME!"); return false; @@ -1433,7 +1437,9 @@ void zfs_set_property() noexcept { } // Set the property - gucc::fs::zfs_set_property(zfs_property_ent, zdataset); + if (!gucc::fs::zfs_set_property(zfs_property_ent, zdataset)) { + spdlog::error("Failed to set zfs property '{}' on dataset '{}'", zfs_property_ent, zdataset); + } } void zfs_destroy_dataset() noexcept {