const refactor
This commit is contained in:
parent
26fa85e421
commit
c7318b0383
@ -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}")
|
||||
|
@ -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_;
|
||||
|
@ -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)
|
||||
|
@ -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<std::string> delimiter = std::nullopt,
|
||||
std::optional<std::string> prefix = std::nullopt) const
|
||||
-> bool;
|
||||
[[nodiscard]] auto get_object_list(
|
||||
std::string &response_data, long &response_code,
|
||||
std::optional<std::string> delimiter = std::nullopt,
|
||||
std::optional<std::string> 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_
|
||||
|
@ -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"
|
||||
|
@ -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<option> option_list = {
|
||||
data_directory_option,
|
||||
drive_information_option,
|
||||
encrypt_option,
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
s3_option,
|
||||
name_option,
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
generate_config_option,
|
||||
get_option,
|
||||
get_directory_items_option,
|
||||
@ -91,27 +91,26 @@ void get_api_authentication_data(std::string &user, std::string &password,
|
||||
std::uint16_t &port, const provider_type &prov,
|
||||
const std::string &data_directory);
|
||||
|
||||
[[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
|
||||
-> provider_type;
|
||||
[[nodiscard]] auto
|
||||
get_provider_type_from_args(std::vector<const char *> args) -> provider_type;
|
||||
|
||||
[[nodiscard]] auto has_option(std::vector<const char *> args,
|
||||
const std::string &option_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto has_option(std::vector<const char *> args, const option &opt)
|
||||
-> bool;
|
||||
[[nodiscard]] auto has_option(std::vector<const char *> args,
|
||||
const option &opt) -> bool;
|
||||
|
||||
[[nodiscard]] auto parse_option(std::vector<const char *> args,
|
||||
const std::string &option_name,
|
||||
std::uint8_t count) -> std::vector<std::string>;
|
||||
|
||||
[[nodiscard]] auto parse_string_option(std::vector<const char *> args,
|
||||
const option &opt, std::string &value)
|
||||
-> exit_code;
|
||||
const option &opt,
|
||||
std::string &value) -> exit_code;
|
||||
|
||||
[[nodiscard]] auto parse_drive_options(std::vector<const char *> args,
|
||||
provider_type &prov,
|
||||
std::string &data_directory)
|
||||
-> std::vector<std::string>;
|
||||
[[nodiscard]] auto
|
||||
parse_drive_options(std::vector<const char *> args, provider_type &prov,
|
||||
std::string &data_directory) -> std::vector<std::string>;
|
||||
} // namespace repertory::utils::cli
|
||||
|
||||
#endif // INCLUDE_UTILS_CLI_UTILS_HPP_
|
||||
|
@ -58,7 +58,7 @@ app_config::app_config(const provider_type &prov,
|
||||
: prov_(prov),
|
||||
api_auth_(utils::generate_random_string(default_api_auth_size)),
|
||||
api_port_(default_rpc_port(prov)),
|
||||
api_user_(REPERTORY),
|
||||
api_user_(std::string{REPERTORY}),
|
||||
config_changed_(false),
|
||||
data_directory_(data_directory.empty()
|
||||
? default_data_directory(prov)
|
||||
|
@ -179,7 +179,7 @@ void packet_server::read_packet(std::shared_ptr<connection> conn,
|
||||
ret = request->decode(version);
|
||||
if (ret == 0) {
|
||||
if (utils::compare_version_strings(
|
||||
version, REPERTORY_MIN_REMOTE_VERSION) >= 0) {
|
||||
version, std::string{REPERTORY_MIN_REMOTE_VERSION}) >= 0) {
|
||||
std::uint32_t service_flags{};
|
||||
DECODE_OR_IGNORE(request, service_flags);
|
||||
|
||||
|
@ -209,7 +209,7 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
|
||||
&(L"\\repertory\\" +
|
||||
std::wstring(file_system_host->FileSystemName()).substr(0, 1))[0u]);
|
||||
}
|
||||
file_system_host->SetFileSystemName(REPERTORY_W);
|
||||
file_system_host->SetFileSystemName(std::wstring{REPERTORY_W}.data());
|
||||
file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
|
||||
file_system_host->SetReparsePoints(FALSE);
|
||||
file_system_host->SetReparsePointsAccessCheck(FALSE);
|
||||
|
@ -57,15 +57,15 @@ E_SIMPLE3(winfsp_event, debug, true,
|
||||
winfsp_drive::winfsp_service::winfsp_service(
|
||||
lock_data &lock, winfsp_drive &drive, std::vector<std::string> drive_args,
|
||||
app_config &config)
|
||||
: Service(static_cast<PWSTR>(REPERTORY_W)),
|
||||
: Service(std::wstring{REPERTORY_W}.data()),
|
||||
lock_(lock),
|
||||
drive_(drive),
|
||||
drive_args_(std::move(drive_args)),
|
||||
host_(drive),
|
||||
config_(config) {}
|
||||
|
||||
auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
|
||||
-> NTSTATUS {
|
||||
auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/,
|
||||
PWSTR * /*Argv*/) -> NTSTATUS {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
const auto mount_location = utils::string::to_lower(
|
||||
@ -438,10 +438,9 @@ auto winfsp_drive::get_item_meta(const std::string &api_path,
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto winfsp_drive::get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size)
|
||||
-> NTSTATUS {
|
||||
auto winfsp_drive::get_security_by_name(
|
||||
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) -> NTSTATUS {
|
||||
const auto api_path =
|
||||
utils::path::create_api_path(utils::string::to_utf8(file_name));
|
||||
|
||||
@ -539,7 +538,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
|
||||
std::wstring(file_system_host->FileSystemName()).substr(0, 1))
|
||||
.data());
|
||||
}
|
||||
file_system_host->SetFileSystemName(REPERTORY_W);
|
||||
file_system_host->SetFileSystemName(std::wstring{REPERTORY_W}.data());
|
||||
file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
|
||||
file_system_host->SetReparsePoints(FALSE);
|
||||
file_system_host->SetReparsePointsAccessCheck(FALSE);
|
||||
@ -697,8 +696,8 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
|
||||
|
||||
auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT32 attributes, BOOLEAN replace_attributes,
|
||||
UINT64 /*allocation_size*/, FileInfo *file_info)
|
||||
-> NTSTATUS {
|
||||
UINT64 /*allocation_size*/,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::string api_path;
|
||||
@ -772,9 +771,8 @@ void winfsp_drive::populate_file_info(const std::string &api_path,
|
||||
populate_file_info(file_size, meta, ofi.FileInfo);
|
||||
}
|
||||
|
||||
auto winfsp_drive::populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info)
|
||||
-> api_error {
|
||||
auto winfsp_drive::populate_file_info(
|
||||
const std::string &api_path, remote::file_info &file_info) -> api_error {
|
||||
api_meta_map meta{};
|
||||
auto ret = provider_.get_item_meta(api_path, meta);
|
||||
if (ret == api_error::success) {
|
||||
@ -807,8 +805,8 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
|
||||
}
|
||||
|
||||
auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
|
||||
UINT64 offset, ULONG length, PULONG bytes_transferred)
|
||||
-> NTSTATUS {
|
||||
UINT64 offset, ULONG length,
|
||||
PULONG bytes_transferred) -> NTSTATUS {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
*bytes_transferred = 0U;
|
||||
@ -859,8 +857,8 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
|
||||
|
||||
auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
PWSTR /*pattern*/, PWSTR marker, PVOID buffer,
|
||||
ULONG buffer_length, PULONG bytes_transferred)
|
||||
-> NTSTATUS {
|
||||
ULONG buffer_length,
|
||||
PULONG bytes_transferred) -> NTSTATUS {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::string api_path;
|
||||
@ -991,8 +989,8 @@ auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
|
||||
auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time,
|
||||
UINT64 change_time, FileInfo *file_info)
|
||||
-> NTSTATUS {
|
||||
UINT64 change_time,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::string api_path;
|
||||
|
@ -93,9 +93,9 @@ auto lock_data::get_mount_state(json &mount_state) -> bool {
|
||||
auto lock_data::get_state_directory() -> std::string {
|
||||
#if defined(__APPLE__)
|
||||
return utils::path::resolve("~/Library/Application Support/" +
|
||||
std::string(REPERTORY_DATA_NAME) + "/state");
|
||||
std::string{REPERTORY_DATA_NAME} + "/state");
|
||||
#else
|
||||
return utils::path::resolve("~/.local/" + std::string(REPERTORY_DATA_NAME) +
|
||||
return utils::path::resolve("~/.local/" + std::string{REPERTORY_DATA_NAME} +
|
||||
"/state");
|
||||
#endif
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ auto lock_data::get_mount_state(json &mount_state) -> bool {
|
||||
HKEY key;
|
||||
auto ret = !::RegCreateKeyEx(
|
||||
HKEY_CURRENT_USER,
|
||||
("SOFTWARE\\" + std::string(REPERTORY_DATA_NAME) + "\\Mounts").c_str(), 0,
|
||||
("SOFTWARE\\" + std::string{REPERTORY_DATA_NAME} + "\\Mounts").c_str(), 0,
|
||||
nullptr, 0, KEY_ALL_ACCESS, nullptr, &key, nullptr);
|
||||
if (ret) {
|
||||
DWORD i = 0u;
|
||||
@ -145,7 +145,7 @@ auto lock_data::set_mount_state(bool active, const std::string &mount_location,
|
||||
HKEY key;
|
||||
if ((ret = !::RegCreateKeyEx(
|
||||
HKEY_CURRENT_USER,
|
||||
("SOFTWARE\\" + std::string(REPERTORY_DATA_NAME) + "\\Mounts")
|
||||
("SOFTWARE\\" + std::string{REPERTORY_DATA_NAME} + "\\Mounts")
|
||||
.c_str(),
|
||||
0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &key, nullptr))) {
|
||||
const auto str = json({{"Active", active},
|
||||
|
@ -43,8 +43,8 @@ inline void create_comm(std::unique_ptr<intf_t> &comm, const config_t &config) {
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
auto create_provider(const provider_type &prov, app_config &config)
|
||||
-> std::unique_ptr<i_provider> {
|
||||
auto create_provider(const provider_type &prov,
|
||||
app_config &config) -> std::unique_ptr<i_provider> {
|
||||
static std::mutex mutex;
|
||||
mutex_lock lock(mutex);
|
||||
|
||||
@ -56,13 +56,13 @@ auto create_provider(const provider_type &prov, app_config &config)
|
||||
config.get_host_config());
|
||||
return std::make_unique<sia_provider>(config, *comm);
|
||||
}
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
case provider_type::s3: {
|
||||
create_comm<i_http_comm, curl_comm, s3_config>(comm,
|
||||
config.get_s3_config());
|
||||
return std::make_unique<s3_provider>(config, *comm);
|
||||
}
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
case provider_type::encrypt: {
|
||||
return std::make_unique<encrypt_provider>(config);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
|
||||
#include "providers/s3/s3_provider.hpp"
|
||||
|
||||
@ -44,9 +44,8 @@ s3_provider::s3_provider(app_config &config, i_http_comm &comm)
|
||||
get_comm().enable_s3_path_style(config.get_s3_config().use_path_style);
|
||||
}
|
||||
|
||||
auto s3_provider::add_if_not_found(api_file &file,
|
||||
const std::string &object_name) const
|
||||
-> api_error {
|
||||
auto s3_provider::add_if_not_found(
|
||||
api_file &file, const std::string &object_name) const -> api_error {
|
||||
api_meta_map meta{};
|
||||
if (get_item_meta(file.api_path, meta) == api_error::item_not_found) {
|
||||
auto err = create_path_directories(
|
||||
@ -141,9 +140,8 @@ auto s3_provider::create_file_extra(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::create_path_directories(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
-> api_error {
|
||||
auto s3_provider::create_path_directories(
|
||||
const std::string &api_path, const std::string &key) const -> api_error {
|
||||
if (api_path == "/") {
|
||||
return api_error::success;
|
||||
}
|
||||
@ -259,9 +257,8 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto s3_provider::get_directory_items_impl(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error {
|
||||
auto s3_provider::get_directory_items_impl(
|
||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
||||
const auto cfg = get_config().get_s3_config();
|
||||
const auto is_encrypted = not cfg.encryption_token.empty();
|
||||
|
||||
@ -375,8 +372,8 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto s3_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error {
|
||||
auto s3_provider::get_file(const std::string &api_path,
|
||||
api_file &file) const -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
try {
|
||||
@ -468,10 +465,9 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::get_object_info(bool directory, const std::string &api_path,
|
||||
bool &is_encrypted, std::string &object_name,
|
||||
head_object_result &result) const
|
||||
-> api_error {
|
||||
auto s3_provider::get_object_info(
|
||||
bool directory, const std::string &api_path, bool &is_encrypted,
|
||||
std::string &object_name, head_object_result &result) const -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
try {
|
||||
@ -518,11 +514,10 @@ auto s3_provider::get_object_info(bool directory, const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto s3_provider::get_object_list(std::string &response_data,
|
||||
long &response_code,
|
||||
std::optional<std::string> delimiter,
|
||||
std::optional<std::string> prefix) const
|
||||
-> bool {
|
||||
auto s3_provider::get_object_list(
|
||||
std::string &response_data, long &response_code,
|
||||
std::optional<std::string> delimiter,
|
||||
std::optional<std::string> prefix) const -> bool {
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.aws_service = "aws:amz:" + get_config().get_s3_config().region + ":s3";
|
||||
@ -579,8 +574,8 @@ auto s3_provider::get_used_drive_space_impl() const -> std::uint64_t {
|
||||
});
|
||||
}
|
||||
|
||||
auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
auto s3_provider::is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
exists = false;
|
||||
@ -607,8 +602,8 @@ auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto s3_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
auto s3_provider::is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
exists = false;
|
||||
@ -893,4 +888,4 @@ auto s3_provider::upload_file_impl(const std::string &api_path,
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // PROJECT_ENABLE_S3
|
||||
|
@ -52,11 +52,11 @@ void get_api_authentication_data(std::string &user, std::string &password,
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_provider_type_from_args(std::vector<const char *> args) -> provider_type {
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
if (has_option(args, options::s3_option)) {
|
||||
return provider_type::s3;
|
||||
}
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
if (has_option(args, options::remote_mount_option)) {
|
||||
return provider_type::remote;
|
||||
}
|
||||
@ -139,10 +139,10 @@ auto parse_drive_options(
|
||||
(std::string(args.at(i)) == options::remote_mount_option.at(1U)) ||
|
||||
(std::string(args.at(i)) == options::data_directory_option.at(0U)) ||
|
||||
(std::string(args.at(i)) == options::data_directory_option.at(1U))
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
|| (std::string(args.at(i)) == options::name_option.at(0U)) ||
|
||||
(std::string(args.at(i)) == options::name_option.at(1U))
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // PROJECT_ENABLE_S3
|
||||
) {
|
||||
i++;
|
||||
continue;
|
||||
@ -164,12 +164,12 @@ auto parse_drive_options(
|
||||
|
||||
const auto fuse_option_list = utils::string::split(options, ',');
|
||||
for (const auto &fuse_option : fuse_option_list) {
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
if (fuse_option.find("s3") == 0) {
|
||||
prov = provider_type::s3;
|
||||
continue;
|
||||
}
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
if ((fuse_option.find("dd") == 0) ||
|
||||
(fuse_option.find("data_directory") == 0)) {
|
||||
const auto data = utils::string::split(fuse_option, '=');
|
||||
|
@ -36,13 +36,13 @@ template <typename drive> inline void help(std::vector<const char *> args) {
|
||||
std::cout << " -di,--drive_information Display mounted drive "
|
||||
"information"
|
||||
<< std::endl;
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
std::cout << " -s3,--s3 Enables S3 mode"
|
||||
<< std::endl;
|
||||
std::cout << " -na,--name Unique name for S3 "
|
||||
"instance [Required]"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
std::cout
|
||||
<< " -gc,--generate_config Generate initial configuration"
|
||||
<< std::endl;
|
||||
@ -72,11 +72,11 @@ template <typename drive> inline void help(std::vector<const char *> args) {
|
||||
std::cout << " -pw,--password Specify API password"
|
||||
<< std::endl;
|
||||
#if !defined(_WIN32)
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
std::cout << " -o s3 Enables S3 mode for "
|
||||
"'fstab' mounts"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#endif // defined(PROJECT_ENABLE_S3)
|
||||
#endif // _WIN32
|
||||
std::cout << " -set,--set [name] [value] Set configuration value"
|
||||
<< std::endl;
|
||||
|
@ -92,7 +92,7 @@ auto main(int argc, char **argv) -> int {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
if ((res == exit_code::success) && (prov == provider_type::s3)) {
|
||||
std::string data;
|
||||
res = utils::cli::parse_string_option(
|
||||
@ -111,7 +111,7 @@ auto main(int argc, char **argv) -> int {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // PROJECT_ENABLE_S3
|
||||
|
||||
int mount_result{};
|
||||
if (res == exit_code::success) {
|
||||
|
@ -47,7 +47,7 @@ protected:
|
||||
void SetUp() override {
|
||||
if (PROVIDER_INDEX != 0) {
|
||||
if (PROVIDER_INDEX == 1) {
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
|
||||
|
@ -535,7 +535,7 @@ TEST(fuse_drive, all_tests) {
|
||||
|
||||
switch (idx) {
|
||||
case 0U: {
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
config_ptr =
|
||||
std::make_unique<app_config>(provider_type::s3, cfg_directory);
|
||||
{
|
||||
|
@ -668,7 +668,7 @@ TEST(providers, encrypt_provider) {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
|
||||
#if defined(PROJECT_ENABLE_S3)
|
||||
TEST(providers, s3_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(get_test_dir(), {"s3_provider"});
|
||||
|
@ -333,7 +333,7 @@ TEST_F(winfsp_test, all_tests) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !defined(REPERTORY_ENABLE_S3)
|
||||
#if !defined(PROJECT_ENABLE_S3)
|
||||
if (PROVIDER_INDEX == 1U) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user