refactor
This commit is contained in:
@ -39,12 +39,11 @@ auto directory_cache::get_directory(std::uint64_t handle)
|
||||
-> std::shared_ptr<directory_iterator> {
|
||||
recur_mutex_lock directory_lock(directory_mutex_);
|
||||
auto iter =
|
||||
std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
std::ranges::find_if(directory_lookup_, [handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
if (iter != directory_lookup_.end()) {
|
||||
return iter->second.iterator;
|
||||
}
|
||||
@ -68,12 +67,11 @@ auto directory_cache::remove_directory(const std::string &api_path)
|
||||
void directory_cache::remove_directory(std::uint64_t handle) {
|
||||
recur_mutex_lock directory_lock(directory_mutex_);
|
||||
auto iter =
|
||||
std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
std::ranges::find_if(directory_lookup_, [handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
if (iter == directory_lookup_.end()) {
|
||||
return;
|
||||
}
|
||||
|
@ -102,10 +102,9 @@ auto directory_iterator::get_directory_item(std::size_t offset,
|
||||
|
||||
auto directory_iterator::get_directory_item(const std::string &api_path,
|
||||
directory_item &di) -> api_error {
|
||||
auto iter =
|
||||
std::find_if(items_.begin(), items_.end(), [&](const auto &item) -> bool {
|
||||
return api_path == item.api_path;
|
||||
});
|
||||
auto iter = std::ranges::find_if(items_, [&api_path](auto &&item) -> bool {
|
||||
return api_path == item.api_path;
|
||||
});
|
||||
if (iter == items_.end()) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@ -126,10 +125,10 @@ auto directory_iterator::get_json(std::size_t offset, json &item) -> int {
|
||||
|
||||
auto directory_iterator::get_next_directory_offset(
|
||||
const std::string &api_path) const -> std::size_t {
|
||||
const auto iter = std::find_if(items_.begin(), items_.end(),
|
||||
[&api_path](const auto &dir_item) -> bool {
|
||||
return api_path == dir_item.api_path;
|
||||
});
|
||||
const auto iter =
|
||||
std::ranges::find_if(items_, [&api_path](auto &&dir_item) -> bool {
|
||||
return api_path == dir_item.api_path;
|
||||
});
|
||||
|
||||
return (iter == items_.end()) ? 0U
|
||||
: static_cast<std::size_t>(
|
||||
|
@ -66,7 +66,7 @@ file_manager::file_manager(app_config &config, i_provider &provider)
|
||||
}
|
||||
|
||||
E_SUBSCRIBE(file_upload_completed,
|
||||
[this](auto &&event) { this->upload_completed(event); });
|
||||
[this](auto &&event) { this->upload_completed(event); });
|
||||
}
|
||||
|
||||
file_manager::~file_manager() {
|
||||
@ -234,10 +234,9 @@ auto file_manager::get_next_handle() -> std::uint64_t {
|
||||
auto file_manager::get_open_file_by_handle(std::uint64_t handle) const
|
||||
-> std::shared_ptr<i_closeable_open_file> {
|
||||
auto file_iter =
|
||||
std::find_if(open_file_lookup_.begin(), open_file_lookup_.end(),
|
||||
[&handle](auto &&item) -> bool {
|
||||
return item.second->has_handle(handle);
|
||||
});
|
||||
std::ranges::find_if(open_file_lookup_, [&handle](auto &&item) -> bool {
|
||||
return item.second->has_handle(handle);
|
||||
});
|
||||
return (file_iter == open_file_lookup_.end()) ? nullptr : file_iter->second;
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,8 @@ namespace {
|
||||
return cfg.bucket;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_last_modified(const nlohmann::json &obj) -> std::uint64_t {
|
||||
[[nodiscard]] auto get_last_modified(const nlohmann::json &obj)
|
||||
-> std::uint64_t {
|
||||
try {
|
||||
return repertory::s3_provider::convert_api_date(
|
||||
obj["modTime"].get<std::string>());
|
||||
@ -63,8 +63,9 @@ namespace repertory {
|
||||
sia_provider::sia_provider(app_config &config, i_http_comm &comm)
|
||||
: base_provider(config, comm) {}
|
||||
|
||||
auto sia_provider::create_directory_impl(
|
||||
const std::string &api_path, api_meta_map & /* meta */) -> api_error {
|
||||
auto sia_provider::create_directory_impl(const std::string &api_path,
|
||||
api_meta_map & /* meta */)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
curl::requests::http_put_file put_file{};
|
||||
@ -138,8 +139,9 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto sia_provider::get_directory_items_impl(
|
||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
||||
auto sia_provider::get_directory_items_impl(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
json object_list{};
|
||||
@ -197,8 +199,8 @@ auto sia_provider::get_directory_items_impl(
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto sia_provider::get_file(const std::string &api_path,
|
||||
api_file &file) const -> api_error {
|
||||
auto sia_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -235,8 +237,9 @@ auto sia_provider::get_file(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto sia_provider::get_file_list(
|
||||
api_file_list &list, std::string & /* marker */) const -> api_error {
|
||||
auto sia_provider::get_file_list(api_file_list &list,
|
||||
std::string & /* marker */) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
using dir_func = std::function<api_error(std::string api_path)>;
|
||||
@ -440,8 +443,8 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto sia_provider::is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -459,11 +462,10 @@ auto sia_provider::is_directory(const std::string &api_path,
|
||||
}
|
||||
|
||||
exists = object_list.contains("entries") &&
|
||||
std::find_if(object_list.at("entries").begin(),
|
||||
object_list.at("entries").end(),
|
||||
[&api_path](const auto &entry) -> bool {
|
||||
return entry.at("name") == (api_path + "/");
|
||||
}) != object_list.at("entries").end();
|
||||
std::ranges::find_if(object_list.at("entries"),
|
||||
[&api_path](auto &&entry) -> bool {
|
||||
return entry.at("name") == (api_path + "/");
|
||||
}) != object_list.at("entries").end();
|
||||
return api_error::success;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_api_path_error(
|
||||
@ -473,8 +475,8 @@ auto sia_provider::is_directory(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto sia_provider::is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto sia_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
|
@ -179,11 +179,8 @@ auto api_error_from_string(std::string_view str) -> api_error {
|
||||
throw startup_exception("undefined api_error strings");
|
||||
}
|
||||
|
||||
const auto iter = std::find_if(
|
||||
LOOKUP.begin(), LOOKUP.end(),
|
||||
[&str](const std::pair<api_error, std::string> &item) -> bool {
|
||||
return item.second == str;
|
||||
});
|
||||
const auto iter = std::ranges::find_if(
|
||||
LOOKUP, [&str](auto &&item) -> bool { return item.second == str; });
|
||||
return iter == LOOKUP.end() ? api_error::error : iter->first;
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ void get_api_authentication_data(std::string &user, std::string &password,
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_provider_type_from_args(std::vector<const char *> args) -> provider_type {
|
||||
[[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
|
||||
-> provider_type {
|
||||
if (has_option(args, options::s3_option)) {
|
||||
return provider_type::s3;
|
||||
}
|
||||
@ -67,12 +67,11 @@ get_provider_type_from_args(std::vector<const char *> args) -> provider_type {
|
||||
return provider_type::sia;
|
||||
}
|
||||
|
||||
auto has_option(std::vector<const char *> args,
|
||||
const std::string &option_name) -> bool {
|
||||
return std::find_if(args.begin(), args.end(),
|
||||
[&option_name](const auto &value) -> bool {
|
||||
return option_name == value;
|
||||
}) != args.end();
|
||||
auto has_option(std::vector<const char *> args, const std::string &option_name)
|
||||
-> bool {
|
||||
return std::ranges::find_if(args, [&option_name](auto &&value) -> bool {
|
||||
return option_name == value;
|
||||
}) != args.end();
|
||||
}
|
||||
|
||||
auto has_option(std::vector<const char *> args, const option &opt) -> bool {
|
||||
@ -80,8 +79,8 @@ auto has_option(std::vector<const char *> args, const option &opt) -> bool {
|
||||
}
|
||||
|
||||
auto parse_option(std::vector<const char *> args,
|
||||
const std::string &option_name,
|
||||
std::uint8_t count) -> std::vector<std::string> {
|
||||
const std::string &option_name, std::uint8_t count)
|
||||
-> std::vector<std::string> {
|
||||
std::vector<std::string> ret;
|
||||
auto found{false};
|
||||
for (std::size_t i = 0U; not found && (i < args.size()); i++) {
|
||||
@ -119,18 +118,18 @@ auto parse_string_option(std::vector<const char *> args, const option &opt,
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto parse_drive_options(
|
||||
std::vector<const char *> args, [[maybe_unused]] provider_type &prov,
|
||||
[[maybe_unused]] std::string &data_directory) -> std::vector<std::string> {
|
||||
auto parse_drive_options(std::vector<const char *> args,
|
||||
[[maybe_unused]] provider_type &prov,
|
||||
[[maybe_unused]] std::string &data_directory)
|
||||
-> std::vector<std::string> {
|
||||
// Strip out options from command line
|
||||
const auto &option_list = options::option_list;
|
||||
std::vector<std::string> drive_args;
|
||||
for (std::size_t i = 0U; i < args.size(); i++) {
|
||||
const auto &arg = args.at(i);
|
||||
if (std::find_if(option_list.begin(), option_list.end(),
|
||||
[&arg](const auto &pair) -> bool {
|
||||
return ((pair.at(0U) == arg) || (pair.at(1U) == arg));
|
||||
}) == option_list.end()) {
|
||||
if (std::ranges::find_if(option_list, [&arg](auto &&pair) -> bool {
|
||||
return ((pair.at(0U) == arg) || (pair.at(1U) == arg));
|
||||
}) == option_list.end()) {
|
||||
drive_args.emplace_back(args.at(i));
|
||||
continue;
|
||||
}
|
||||
|
@ -421,19 +421,19 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
decrypt_parts(cfg, dir_item.api_path);
|
||||
}
|
||||
|
||||
auto dir = std::find_if(list_decrypted.begin(), list_decrypted.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return dir_item.directory;
|
||||
});
|
||||
auto dir =
|
||||
std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
|
||||
return dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(dir, list_decrypted.end());
|
||||
EXPECT_STREQ("/sub10", dir->api_path.c_str());
|
||||
EXPECT_STREQ("/", dir->api_parent.c_str());
|
||||
EXPECT_EQ(std::size_t(0U), dir->size);
|
||||
|
||||
auto file = std::find_if(list_decrypted.begin(), list_decrypted.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
auto file =
|
||||
std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(file, list_decrypted.end());
|
||||
EXPECT_STREQ("/test.txt", file->api_path.c_str());
|
||||
EXPECT_STREQ("/", file->api_parent.c_str());
|
||||
@ -460,10 +460,10 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
decrypt_parts(cfg, dir_item.api_path);
|
||||
}
|
||||
|
||||
auto file2 = std::find_if(list_decrypted2.begin(), list_decrypted2.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
auto file2 =
|
||||
std::ranges::find_if(list_decrypted2, [](auto &&dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(file2, list_decrypted2.end());
|
||||
EXPECT_STREQ("/sub10/moose.txt", file2->api_path.c_str());
|
||||
EXPECT_STREQ("/sub10", file2->api_parent.c_str());
|
||||
|
Reference in New Issue
Block a user