refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-04-03 19:34:42 -05:00
parent 4f2ee2ad99
commit 8d2024d34b
2 changed files with 30 additions and 19 deletions

View File

@ -52,6 +52,9 @@ private:
[[nodiscard]] auto create_directory_key(const std::string &api_path) const [[nodiscard]] auto create_directory_key(const std::string &api_path) const
-> repertory::api_error; -> repertory::api_error;
[[nodiscard]] auto ensure_directory_exists(const std::string &api_path) const
-> api_error;
[[nodiscard]] auto get_object_info(const std::string &api_path, [[nodiscard]] auto get_object_info(const std::string &api_path,
json &object_info) const -> api_error; json &object_info) const -> api_error;

View File

@ -159,14 +159,14 @@ auto sia_provider::create_directory_key(const std::string &api_path) const
} }
if (not object_list.contains("objects")) { if (not object_list.contains("objects")) {
return api_error::item_not_found; return api_error::directory_not_found;
} }
const auto &list = object_list.at("objects"); const auto &list = object_list.at("objects");
if (std::ranges::find_if(list, [&api_path](auto &&entry) -> bool { if (std::ranges::find_if(list, [&api_path](auto &&entry) -> bool {
return entry.at("key").template get<std::string>() == api_path + '/'; return entry.at("key").template get<std::string>() == api_path + '/';
}) == list.end()) { }) == list.end()) {
return api_error::item_not_found; return api_error::directory_not_found;
} }
api_meta_map meta; api_meta_map meta;
@ -174,6 +174,27 @@ auto sia_provider::create_directory_key(const std::string &api_path) const
meta); meta);
} }
auto sia_provider::ensure_directory_exists(const std::string &api_path) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME();
bool exists{};
auto res{is_directory(api_path, exists)};
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed detect existing directory");
return res;
}
if (not exists) {
utils::error::raise_api_path_error(function_name, api_path, res,
"directory not found");
return api_error::directory_not_found;
}
return api_error::success;
}
auto sia_provider::get_directory_item_count(const std::string &api_path) const auto sia_provider::get_directory_item_count(const std::string &api_path) const
-> std::uint64_t { -> std::uint64_t {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
@ -241,20 +262,13 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
: entry["size"].get<std::uint64_t>(), : entry["size"].get<std::uint64_t>(),
get_last_modified(entry)); get_last_modified(entry));
if (directory) { if (directory) {
bool exists{}; auto res{ensure_directory_exists(entry_api_path)};
auto res{is_directory(entry_api_path, exists)};
if (res != api_error::success) { if (res != api_error::success) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, entry_api_path, res, function_name, entry_api_path, res,
"failed detect existing directory"); "failed detect existing directory");
continue; continue;
} }
if (not exists) {
utils::error::raise_api_path_error(function_name, entry_api_path,
res, "directory not found");
continue;
}
} }
get_api_item_added()(directory, file); get_api_item_added()(directory, file);
@ -364,8 +378,7 @@ auto sia_provider::get_file_list(api_file_list &list,
get_last_modified(entry)), get_last_modified(entry)),
}; };
bool exists{}; auto res{ensure_directory_exists(entry_api_path)};
auto res{is_directory(entry_api_path, exists)};
if (res != api_error::success) { if (res != api_error::success) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, entry_api_path, res, function_name, entry_api_path, res,
@ -373,12 +386,6 @@ auto sia_provider::get_file_list(api_file_list &list,
return res; return res;
} }
if (not exists) {
utils::error::raise_api_path_error(
function_name, entry_api_path, res, "directory not found");
return api_error::directory_not_found;
}
get_api_item_added()(true, dir); get_api_item_added()(true, dir);
} }
@ -578,7 +585,8 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
} }
} }
if (res == api_error::item_not_found) { if (res == api_error::directory_not_found ||
res == api_error::item_not_found) {
return api_error::success; return api_error::success;
} }