From 3814b9797dcd192a461b7a206d08a31a961360cb Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 2 Dec 2024 13:54:02 -0600 Subject: [PATCH] refactor --- .../src/providers/s3/s3_provider.cpp | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 534f0639..47f41e03 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -417,25 +417,27 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path, for (auto &&node : node_list) { auto child_object_name = utils::path::create_api_path( node.node().select_node("Key").node().text().as_string()); - if (child_object_name != utils::path::create_api_path(prefix)) { - auto size = node.node().select_node("Size").node().text().as_ullong(); - auto last_modified = convert_api_date( - node.node().select_node("LastModified").node().text().as_string()); - add_directory_item( - false, child_object_name, last_modified, - [this, &is_encrypted, - &size](const directory_item &dir_item) -> std::uint64_t { - std::string size_str; - if (get_item_meta(dir_item.api_path, META_SIZE, size_str) == - api_error::success) { - return utils::string::to_uint64(size_str); - } - - return is_encrypted ? utils::encryption::encrypting_reader:: - calculate_decrypted_size(size) - : size; - }); + if (child_object_name == utils::path::create_api_path(prefix)) { + continue; } + + auto size = node.node().select_node("Size").node().text().as_ullong(); + auto last_modified = convert_api_date( + node.node().select_node("LastModified").node().text().as_string()); + add_directory_item(false, child_object_name, last_modified, + [this, &is_encrypted, &size]( + const directory_item &dir_item) -> std::uint64_t { + std::string size_str; + if (get_item_meta(dir_item.api_path, META_SIZE, + size_str) == api_error::success) { + return utils::string::to_uint64(size_str); + } + + return is_encrypted + ? utils::encryption::encrypting_reader:: + calculate_decrypted_size(size) + : size; + }); } } @@ -521,40 +523,39 @@ auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const for (auto &&node : node_list) { auto api_path = std::string{node.node().select_node("Key").node().text().as_string()}; - if (not utils::string::ends_with(api_path, "/")) { - auto is_encrypted = - not get_config().get_s3_config().encryption_token.empty(); - if (is_encrypted) { - auto err = decrypt_object_name(api_path); - if (err != api_error::success) { - return err; - } - } + if (utils::string::ends_with(api_path, "/")) { + continue; + } - auto size = node.node().select_node("Size").node().text().as_ullong(); - - api_file file{}; - file.api_path = utils::path::create_api_path(api_path); - file.api_parent = utils::path::get_parent_api_path(file.api_path); - file.accessed_date = file.changed_date = file.creation_date = - file.modified_date = convert_api_date(node.node() - .select_node("LastModified") - .node() - .text() - .as_string()); - file.file_size = - is_encrypted - ? utils::encryption::encrypting_reader::calculate_decrypted_size( - size) - : size; - file.key = is_encrypted ? utils::path::create_api_path(api_path) : ""; - auto err = add_if_not_found(file, api_path); + auto is_encrypted = + not get_config().get_s3_config().encryption_token.empty(); + if (is_encrypted) { + auto err = decrypt_object_name(api_path); if (err != api_error::success) { return err; } - - list.push_back(std::move(file)); } + + auto size = node.node().select_node("Size").node().text().as_ullong(); + + api_file file{}; + file.api_path = utils::path::create_api_path(api_path); + file.api_parent = utils::path::get_parent_api_path(file.api_path); + file.accessed_date = file.changed_date = file.creation_date = + file.modified_date = convert_api_date( + node.node().select_node("LastModified").node().text().as_string()); + file.file_size = + is_encrypted + ? utils::encryption::encrypting_reader::calculate_decrypted_size( + size) + : size; + file.key = is_encrypted ? utils::path::create_api_path(api_path) : ""; + auto err = add_if_not_found(file, api_path); + if (err != api_error::success) { + return err; + } + + list.push_back(std::move(file)); } return grab_more ? api_error::more_data : api_error::success;