From c7318b0383be6cb3465f396c20cff11e1795a144 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 17 Jul 2024 13:53:56 -0500 Subject: [PATCH] const refactor --- project.cmake | 6 +- repertory/librepertory/include/app_config.hpp | 2 +- repertory/librepertory/include/common.hpp | 13 +-- .../include/providers/s3/s3_provider.hpp | 87 +++++++++---------- repertory/librepertory/include/types/s3.hpp | 2 +- .../librepertory/include/utils/cli_utils.hpp | 27 +++--- repertory/librepertory/src/app_config.cpp | 2 +- .../src/comm/packet/packet_server.cpp | 2 +- .../remotewinfsp/remote_winfsp_drive.cpp | 2 +- .../src/drives/winfsp/winfsp_drive.cpp | 36 ++++---- .../src/platform/unix_platform.cpp | 4 +- .../src/platform/win32_platform.cpp | 4 +- .../librepertory/src/providers/provider.cpp | 8 +- .../src/providers/s3/s3_provider.cpp | 47 +++++----- .../librepertory/src/utils/cli_utils.cpp | 12 +-- repertory/repertory/include/cli/help.hpp | 8 +- repertory/repertory/main.cpp | 4 +- .../include/fixtures/winfsp_fixture.hpp | 2 +- .../repertory_test/src/fuse_drive_test.cpp | 2 +- .../repertory_test/src/providers_test.cpp | 2 +- repertory/repertory_test/src/winfsp_test.cpp | 2 +- 21 files changed, 132 insertions(+), 142 deletions(-) diff --git a/project.cmake b/project.cmake index c0adc36c..f670899c 100644 --- a/project.cmake +++ b/project.cmake @@ -1,6 +1,6 @@ -option(REPERTORY_ENABLE_S3 "Enable S3 support" ON) -if (REPERTORY_ENABLE_S3) - add_definitions(-DREPERTORY_ENABLE_S3) +option(PROJECT_ENABLE_S3 "Enable S3 support" ON) +if (PROJECT_ENABLE_S3) + add_definitions(-DPROJECT_ENABLE_S3) endif() set(CMAKE_CXX_FLAGS "-include common.hpp ${CMAKE_CXX_FLAGS}") diff --git a/repertory/librepertory/include/app_config.hpp b/repertory/librepertory/include/app_config.hpp index 7710236a..52587b40 100644 --- a/repertory/librepertory/include/app_config.hpp +++ b/repertory/librepertory/include/app_config.hpp @@ -101,7 +101,7 @@ private: std::string cache_directory_; host_config hc_; s3_config s3_config_; - std::uint64_t version_ = REPERTORY_CONFIG_VERSION; + std::uint64_t version_{REPERTORY_CONFIG_VERSION}; std::string log_directory_; mutable std::recursive_mutex read_write_mutex_; mutable std::recursive_mutex remote_mount_mutex_; diff --git a/repertory/librepertory/include/common.hpp b/repertory/librepertory/include/common.hpp index 520949c6..0c09bb3a 100644 --- a/repertory/librepertory/include/common.hpp +++ b/repertory/librepertory/include/common.hpp @@ -160,11 +160,12 @@ REPERTORY_IGNORE_WARNINGS_DISABLE() using namespace std::chrono_literals; using json = nlohmann::json; -#define REPERTORY "repertory" -#define REPERTORY_CONFIG_VERSION 0ull -#define REPERTORY_DATA_NAME "repertory2" -#define REPERTORY_MIN_REMOTE_VERSION "2.0.0" -#define REPERTORY_W L"repertory" +inline constexpr const std::string_view REPERTORY = "repertory"; +inline constexpr const std::wstring_view REPERTORY_W = L"repertory"; + +inline constexpr const std::uint64_t REPERTORY_CONFIG_VERSION = 0ULL; +inline constexpr const std::string_view REPERTORY_DATA_NAME = REPERTORY "2"; +inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0"; #if defined(_WIN32) #define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE @@ -176,7 +177,7 @@ using native_handle = HANDLE; using native_handle = int; #endif -constexpr const auto NANOS_PER_SECOND = 1000000000L; +inline constexpr const auto NANOS_PER_SECOND = 1000000000L; #if defined(_WIN32) #if defined(CreateDirectory) diff --git a/repertory/librepertory/include/providers/s3/s3_provider.hpp b/repertory/librepertory/include/providers/s3/s3_provider.hpp index 61cffbd8..5234f008 100644 --- a/repertory/librepertory/include/providers/s3/s3_provider.hpp +++ b/repertory/librepertory/include/providers/s3/s3_provider.hpp @@ -21,7 +21,7 @@ */ #ifndef INCLUDE_PROVIDERS_S3_S3_PROVIDER_HPP_ #define INCLUDE_PROVIDERS_S3_S3_PROVIDER_HPP_ -#if defined(REPERTORY_ENABLE_S3) +#if defined(PROJECT_ENABLE_S3) #include "providers/base_provider.hpp" #include "types/repertory.hpp" @@ -45,64 +45,62 @@ public: auto operator=(s3_provider &&) -> s3_provider & = delete; private: - [[nodiscard]] auto add_if_not_found(api_file &file, - const std::string &object_name) const - -> api_error; + [[nodiscard]] auto + add_if_not_found(api_file &file, + const std::string &object_name) const -> api_error; - [[nodiscard]] auto create_file_extra(const std::string &api_path, - api_meta_map &meta) - -> api_error override; + [[nodiscard]] auto + create_file_extra(const std::string &api_path, + api_meta_map &meta) -> api_error override; - [[nodiscard]] auto create_path_directories(const std::string &api_path, - const std::string &key) const - -> api_error; + [[nodiscard]] auto + create_path_directories(const std::string &api_path, + const std::string &key) const -> api_error; - [[nodiscard]] auto decrypt_object_name(std::string &object_name) const - -> api_error; + [[nodiscard]] auto + decrypt_object_name(std::string &object_name) const -> api_error; [[nodiscard]] auto get_object_info(bool directory, const std::string &api_path, bool &is_encrypted, std::string &object_name, head_object_result &result) const -> api_error; - [[nodiscard]] auto - get_object_list(std::string &response_data, long &response_code, - std::optional delimiter = std::nullopt, - std::optional prefix = std::nullopt) const - -> bool; + [[nodiscard]] auto get_object_list( + std::string &response_data, long &response_code, + std::optional delimiter = std::nullopt, + std::optional prefix = std::nullopt) const -> bool; protected: - [[nodiscard]] auto create_directory_impl(const std::string &api_path, - api_meta_map &meta) - -> api_error override; + [[nodiscard]] auto + create_directory_impl(const std::string &api_path, + api_meta_map &meta) -> api_error override; [[nodiscard]] auto get_directory_items_impl(const std::string &api_path, directory_item_list &list) const -> api_error override; - [[nodiscard]] auto get_used_drive_space_impl() const - -> std::uint64_t override; + [[nodiscard]] auto + get_used_drive_space_impl() const -> std::uint64_t override; - [[nodiscard]] auto remove_directory_impl(const std::string &api_path) - -> api_error override; + [[nodiscard]] auto + remove_directory_impl(const std::string &api_path) -> api_error override; - [[nodiscard]] auto remove_file_impl(const std::string &api_path) - -> api_error override; + [[nodiscard]] auto + remove_file_impl(const std::string &api_path) -> api_error override; - [[nodiscard]] auto upload_file_impl(const std::string &api_path, - const std::string &source_path, - stop_type &stop_requested) - -> api_error override; + [[nodiscard]] auto + upload_file_impl(const std::string &api_path, const std::string &source_path, + stop_type &stop_requested) -> api_error override; public: [[nodiscard]] auto get_directory_item_count(const std::string &api_path) const -> std::uint64_t override; - [[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const - -> api_error override; + [[nodiscard]] auto get_file(const std::string &api_path, + api_file &file) const -> api_error override; - [[nodiscard]] auto get_file_list(api_file_list &list) const - -> api_error override; + [[nodiscard]] auto + get_file_list(api_file_list &list) const -> api_error override; [[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override; @@ -115,8 +113,8 @@ public: [[nodiscard]] auto is_directory(const std::string &api_path, bool &exists) const -> api_error override; - [[nodiscard]] auto is_file(const std::string &api_path, bool &exists) const - -> api_error override; + [[nodiscard]] auto is_file(const std::string &api_path, + bool &exists) const -> api_error override; [[nodiscard]] auto is_online() const -> bool override; @@ -124,15 +122,14 @@ public: return false; }; - [[nodiscard]] auto read_file_bytes(const std::string &api_path, - std::size_t size, std::uint64_t offset, - data_buffer &data, - stop_type &stop_requested) - -> api_error override; + [[nodiscard]] auto + read_file_bytes(const std::string &api_path, std::size_t size, + std::uint64_t offset, data_buffer &data, + stop_type &stop_requested) -> api_error override; - [[nodiscard]] auto rename_file(const std::string &from_api_path, - const std::string &to_api_path) - -> api_error override; + [[nodiscard]] auto + rename_file(const std::string &from_api_path, + const std::string &to_api_path) -> api_error override; [[nodiscard]] auto start(api_item_added_callback api_item_added, i_file_manager *mgr) -> bool override; @@ -141,5 +138,5 @@ public: }; } // namespace repertory -#endif // REPERTORY_ENABLE_S3 +#endif // PROJECT_ENABLE_S3 #endif // INCLUDE_PROVIDERS_S3_S3_PROVIDER_HPP_ diff --git a/repertory/librepertory/include/types/s3.hpp b/repertory/librepertory/include/types/s3.hpp index badbcae5..0aaa8bfa 100644 --- a/repertory/librepertory/include/types/s3.hpp +++ b/repertory/librepertory/include/types/s3.hpp @@ -21,7 +21,7 @@ */ #ifndef INCLUDE_TYPES_S3_HPP_ #define INCLUDE_TYPES_S3_HPP_ -#if defined(REPERTORY_ENABLE_S3) +#if defined(PROJECT_ENABLE_S3) #include "types/repertory.hpp" #include "utils/string_utils.hpp" diff --git a/repertory/librepertory/include/utils/cli_utils.hpp b/repertory/librepertory/include/utils/cli_utils.hpp index 96e998f7..a73dd469 100644 --- a/repertory/librepertory/include/utils/cli_utils.hpp +++ b/repertory/librepertory/include/utils/cli_utils.hpp @@ -33,10 +33,10 @@ static const option display_config_option = {"-dc", "--display_config"}; static const option data_directory_option = {"-dd", "--data_directory"}; static const option encrypt_option = {"-en", "--encrypt"}; static const option drive_information_option = {"-di", "--drive_information"}; -#if defined(REPERTORY_ENABLE_S3) +#if defined(PROJECT_ENABLE_S3) static const option name_option = {"-na", "--name"}; static const option s3_option = {"-s3", "--s3"}; -#endif // defined(REPERTORY_ENABLE_S3) +#endif // defined(PROJECT_ENABLE_S3) static const option generate_config_option = {"-gc", "--generate_config"}; static const option get_option = {"-get", "--get"}; static const option get_directory_items_option = {"-gdi", @@ -62,10 +62,10 @@ static const std::vector