partial remove support
This commit is contained in:
@@ -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 {
|
||||
|
66
repertory/repertory/include/cli/remove.hpp
Normal file
66
repertory/repertory/include/cli/remove.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
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<const char *> /* 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<std::int32_t>(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<data_buffer>(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<std::int32_t>(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_
|
Reference in New Issue
Block a user