From 4fef036f106ff2a3c7ace8a46a31bc28c872c6dd Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 1 Jan 2025 01:19:59 -0600 Subject: [PATCH] refactor --- .../src/providers/s3/s3_provider.cpp | 4 ++-- support/src/utils/encryption.cpp | 20 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index cbfe24a6..136ae5e4 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -600,11 +600,11 @@ auto s3_provider::get_file_list(api_file_list &list, for (const auto &node : node_list) { auto object_name = std::string{node.node().select_node("Key").node().text().as_string()}; - auto api_path{object_name}; - if (utils::string::ends_with(api_path, "/")) { + if (utils::string::ends_with(object_name, "/")) { continue; } + auto api_path{object_name}; auto is_encrypted = not get_s3_config().encryption_token.empty(); if (is_encrypted) { auto res = decrypt_object_name(api_path); diff --git a/support/src/utils/encryption.cpp b/support/src/utils/encryption.cpp index 626a9c99..00b102ae 100644 --- a/support/src/utils/encryption.cpp +++ b/support/src/utils/encryption.cpp @@ -25,26 +25,27 @@ #include "utils/collection.hpp" #include "utils/encrypting_reader.hpp" +#include "utils/path.hpp" namespace repertory::utils::encryption { auto decrypt_file_path(std::string_view encryption_token, std::string &file_path) -> bool { - std::string decrypted_file_path{}; + std::vector decrypted_parts; for (const auto &part : std::filesystem::path(file_path)) { auto file_name = part.string(); if (file_name == "/") { continue; } - auto res = decrypt_file_name(encryption_token, file_name); - if (not res) { - return res; + if (not decrypt_file_name(encryption_token, file_name)) { + return false; } - decrypted_file_path += '/' + file_name; + decrypted_parts.push_back(file_name); } - file_path = decrypted_file_path; + file_path = + utils::path::create_api_path(utils::string::join(decrypted_parts, '/')); return true; } @@ -56,12 +57,7 @@ auto decrypt_file_name(std::string_view encryption_token, } file_name.clear(); - if (not utils::encryption::decrypt_data(encryption_token, buffer, - file_name)) { - return false; - } - - return true; + return utils::encryption::decrypt_data(encryption_token, buffer, file_name); } #if defined(PROJECT_ENABLE_CURL)