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