From 5e8bce5d6357ccb4b0f0b1b84339830721464d30 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 15 Sep 2025 12:19:08 -0500 Subject: [PATCH] partial remove support --- .../librepertory/include/types/repertory.hpp | 3 +- repertory/repertory/include/cli/remove.hpp | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 repertory/repertory/include/cli/remove.hpp diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index d2f37890..dfa2770b 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -204,7 +204,8 @@ enum class exit_code : std::int32_t { ui_mount_failed = -19, exception = -20, provider_offline = -21, - ui_failed = -22 + ui_failed = -22, + remove_failed = -23 }; enum http_error_codes : std::int32_t { diff --git a/repertory/repertory/include/cli/remove.hpp b/repertory/repertory/include/cli/remove.hpp new file mode 100644 index 00000000..5e824cdf --- /dev/null +++ b/repertory/repertory/include/cli/remove.hpp @@ -0,0 +1,66 @@ +/* + Copyright <2018-2025> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef REPERTORY_INCLUDE_CLI_REMOVE_HPP_ +#define REPERTORY_INCLUDE_CLI_REMOVE_HPP_ + +#include "cli/common.hpp" + +#include "utils/string.hpp" +#include "utils/time.hpp" + +namespace repertory::cli::actions { +[[nodiscard]] inline auto +remove(std::vector /* args */, const std::string &data_directory, + provider_type prov, const std::string &unique_id, std::string /* user */, + std::string /* password */) -> exit_code { + lock_data lock(prov, unique_id); + auto res = lock.grab_lock(1); + if (res != lock_result::success) { + std::cout << static_cast(exit_code::lock_failed) << std::endl; + std::cerr << "FATAL: Unable to get provider lock" << std::endl; + return exit_code::lock_failed; + } + + auto trash_path = utils::path::combine( + app_config::get_root_data_directory(), + { + "trash", + app_config::get_provider_name(prov), + unique_id, + fmt::format("{}_{}", utils::time::get_current_time_utc(), + utils::collection::to_hex_string( + utils::generate_secure_random(4U))), + }); + if (utils::file::directory{data_directory}.move_to(trash_path)) { + fmt::println("0"); + fmt::println("successfully removed provider|type|{}|id|{}", + app_config::get_provider_name(prov), unique_id); + return exit_code::success; + } + + std::cout << static_cast(exit_code::remove_failed) << std::endl; + std::cerr << "FATAL: Failed to remove|" << data_directory << std::endl; + return exit_code::remove_failed; +} +} // namespace repertory::cli::actions + +#endif // REPERTORY_INCLUDE_CLI_REMOVE_HPP_