diff --git a/CMakeLists.txt b/CMakeLists.txt index cc9b422..465901b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,13 +38,13 @@ CPMAddPackage( CPMAddPackage( NAME fmt GITHUB_REPOSITORY fmtlib/fmt - GIT_TAG 864465419079791bf61bcf51e633cab6e6be71bb + GIT_TAG 756822ba39941e1e033f26e4c07547cc7058948c EXCLUDE_FROM_ALL YES ) CPMAddPackage( NAME spdlog GITHUB_REPOSITORY gabime/spdlog - GIT_TAG 298a200f69d66114adde2d5d8ad34f2cce5a5b69 + GIT_TAG b75edfafca581e33be29ab51b9546b2e955c2853 EXCLUDE_FROM_ALL YES ) CPMAddPackage( @@ -56,13 +56,13 @@ CPMAddPackage( CPMAddPackage( NAME cpr GITHUB_REPOSITORY libcpr/cpr - GIT_TAG 2157a3126c2ef1b76f339dedd6d7585e39651512 + GIT_TAG 5ae5fdeadfbbb784192c034be0222016123c94ad EXCLUDE_FROM_ALL YES ) CPMAddPackage( NAME range-v3 GITHUB_REPOSITORY ericniebler/range-v3 - GIT_TAG 0fa54d7de5dc00655e38a08e87cda61f7aa6d5b9 + GIT_TAG 3d6e6f56e5e1a3ec4befcc7695504ea23e1d52ab EXCLUDE_FROM_ALL YES ) diff --git a/src/disk.cpp b/src/disk.cpp index 5165309..4277e09 100644 --- a/src/disk.cpp +++ b/src/disk.cpp @@ -141,7 +141,15 @@ void zfs_create_dataset(const std::string_view& zpath, const std::string_view& z #ifdef NDEVENV utils::exec(fmt::format(FMT_COMPILE("zfs create -o mountpoint={} {} 2>>/tmp/cachyos-install.log"), zmount, zpath), true); #else - spdlog::debug("zfs create -o mountpoint={} {} 2>>/tmp/cachyos-install.log", zmount, zpath); + spdlog::debug("zfs create -o mountpoint={} {}", zmount, zpath); +#endif +} + +void zfs_destroy_dataset(const std::string_view& zdataset) noexcept { +#ifdef NDEVENV + utils::exec(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset), true); +#else + spdlog::debug("zfs destroy -r {}", zdataset); #endif } @@ -160,6 +168,7 @@ std::string zfs_list_devs() noexcept { } std::string zfs_list_datasets(const std::string_view& type) noexcept { +#ifdef NDEVENV if (type == "zvol") { return utils::exec("zfs list -Ht volume -o name,volsize 2>/dev/null"); } else if (type == "legacy") { @@ -167,6 +176,9 @@ std::string zfs_list_datasets(const std::string_view& type) noexcept { } return utils::exec("zfs list -H -o name 2>/dev/null | grep \"/\""); +#else + return "zpcachyos"; +#endif } // Other filesystems diff --git a/src/disk.hpp b/src/disk.hpp index dc60df5..7d4dddd 100644 --- a/src/disk.hpp +++ b/src/disk.hpp @@ -19,6 +19,7 @@ std::vector lvm_show_vg() noexcept; // ZFS filesystem void zfs_create_dataset(const std::string_view& zpath, const std::string_view& zmount) noexcept; +void zfs_destroy_dataset(const std::string_view& zdataset) noexcept; std::string zfs_list_devs() noexcept; std::string zfs_list_datasets(const std::string_view& type = "none") noexcept; diff --git a/src/tui.cpp b/src/tui.cpp index 6b5fa34..849dffa 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -1466,6 +1466,84 @@ bool zfs_create_zpool() noexcept { return true; } +void zfs_import_pool() noexcept { +} + +void zfs_new_ds() noexcept { +} + +void zfs_set_property() noexcept { + const auto& zlist = utils::make_multiline(utils::zfs_list_datasets()); + if (zlist.empty()) { + // no available datasets + detail::infobox_widget("\nNo datasets available\"\n"); + std::this_thread::sleep_for(std::chrono::seconds(3)); + return; + } + + std::string zdataset{}; + { + auto screen = ScreenInteractive::Fullscreen(); + std::int32_t selected{}; + bool success{}; + auto ok_callback = [&] { + zdataset = zlist[static_cast(selected)]; + success = true; + screen.ExitLoopClosure()(); + }; + static constexpr auto zfs_menu_body = "\nEnter the property and value you would like to\nset using the format property=mountpoint\n \nFor example, you could enter:\ncompression=lz4\nor\nacltype=posixacl\n"; + const auto& content_size = size(HEIGHT, LESS_THAN, 10) | size(WIDTH, GREATER_THAN, 40); + detail::menu_widget(zlist, ok_callback, &selected, &screen, zfs_menu_body, {size(HEIGHT, LESS_THAN, 18), content_size}); + /* clang-format off */ + if (!success) { return; } + /* clang-format on */ + } + + // const auto& content = fmt::format(FMT_COMPILE("\nPlease confirm that you want to irrevocably\ndelete all the data on '{}'\nand the data contained on all of it's children\n"), zdataset); + // const auto& do_destroy = detail::yesno_widget(content, size(HEIGHT, LESS_THAN, 20) | size(WIDTH, LESS_THAN, 75)); + /* clang-format off */ + //if (!do_destroy) { return; } + /* clang-format on */ + + // utils::zfs_destroy_dataset(zdataset); +} + +void zfs_destroy_dataset() noexcept { + const auto& zlist = utils::make_multiline(utils::zfs_list_datasets()); + if (zlist.empty()) { + // no available datasets + detail::infobox_widget("\nNo datasets available\"\n"); + std::this_thread::sleep_for(std::chrono::seconds(3)); + return; + } + + std::string zdataset{}; + { + auto screen = ScreenInteractive::Fullscreen(); + std::int32_t selected{}; + bool success{}; + auto ok_callback = [&] { + zdataset = zlist[static_cast(selected)]; + success = true; + screen.ExitLoopClosure()(); + }; + static constexpr auto zfs_destroy_menu_body = "\nSelect the dataset you would like to permanently delete.\nPlease note that this will recursively delete any child datasets with warning\n"; + const auto& content_size = size(HEIGHT, LESS_THAN, 10) | size(WIDTH, GREATER_THAN, 40); + detail::menu_widget(zlist, ok_callback, &selected, &screen, zfs_destroy_menu_body, {size(HEIGHT, LESS_THAN, 18), content_size}); + /* clang-format off */ + if (!success) { return; } + /* clang-format on */ + } + + const auto& content = fmt::format(FMT_COMPILE("\nPlease confirm that you want to irrevocably\ndelete all the data on '{}'\nand the data contained on all of it's children\n"), zdataset); + const auto& do_destroy = detail::yesno_widget(content, size(HEIGHT, LESS_THAN, 20) | size(WIDTH, LESS_THAN, 75)); + /* clang-format off */ + if (!do_destroy) { return; } + /* clang-format on */ + + utils::zfs_destroy_dataset(zdataset); +} + // Automated configuration of zfs. Creates a new zpool and a default set of filesystems void zfs_auto() noexcept { // first we need to create a zpool to hold the datasets/zvols @@ -1513,27 +1591,27 @@ void zfs_menu_manual() noexcept { std::int32_t selected{}; auto ok_callback = [&] { switch (selected) { - /*case 0: - zfs_create_zpool(); + case 0: + tui::zfs_create_zpool(); break; - case 1: - zfs_import_pool(); + /*case 1: + tui::zfs_import_pool(); break; case 2: - zfs_new_ds(); + tui::zfs_new_ds(); break; case 3: - zfs_new_ds("legacy"); + tui::zfs_new_ds("legacy"); break; case 4: - zfs_new_ds("zvol"); - break; + tui::zfs_new_ds("zvol"); + break;*/ case 5: - zfs_set_property(); + tui::zfs_set_property(); break; case 6: - zfs_destroy_dataset(); - break;*/ + tui::zfs_destroy_dataset(); + break; default: screen.ExitLoopClosure()(); return; diff --git a/subprojects/cpr.wrap b/subprojects/cpr.wrap index 8998e0a..ea7c795 100644 --- a/subprojects/cpr.wrap +++ b/subprojects/cpr.wrap @@ -1,6 +1,6 @@ [wrap-git] url = https://github.com/libcpr/cpr.git -revision = 2157a3126c2ef1b76f339dedd6d7585e39651512 +revision = 5ae5fdeadfbbb784192c034be0222016123c94ad patch_directory = cpr diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap index c3be08e..3a07bd8 100644 --- a/subprojects/fmt.wrap +++ b/subprojects/fmt.wrap @@ -1,6 +1,6 @@ [wrap-git] url = https://github.com/fmtlib/fmt.git -revision = 864465419079791bf61bcf51e633cab6e6be71bb +revision = 756822ba39941e1e033f26e4c07547cc7058948c patch_directory = fmt diff --git a/subprojects/range-v3.wrap b/subprojects/range-v3.wrap index df60f25..0d5b5d2 100644 --- a/subprojects/range-v3.wrap +++ b/subprojects/range-v3.wrap @@ -1,6 +1,6 @@ [wrap-git] url = https://github.com/ericniebler/range-v3.git -revision = 0fa54d7de5dc00655e38a08e87cda61f7aa6d5b9 +revision = 3d6e6f56e5e1a3ec4befcc7695504ea23e1d52ab patch_directory = range-v3 diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap index 44b1b7f..709ca67 100644 --- a/subprojects/spdlog.wrap +++ b/subprojects/spdlog.wrap @@ -1,6 +1,6 @@ [wrap-git] url = https://github.com/gabime/spdlog.git -revision = 298a200f69d66114adde2d5d8ad34f2cce5a5b69 +revision = b75edfafca581e33be29ab51b9546b2e955c2853 patch_directory = spdlog