From cfa96f24768623ba9df8576cfb16f4fc8009e00e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 20 Dec 2024 13:14:42 -0600 Subject: [PATCH] refactor app config --- .../drives/remote/remote_server_base.hpp | 6 +- .../src/drives/fuse/fuse_drive.cpp | 66 ++++++++++--------- .../src/drives/winfsp/winfsp_drive.cpp | 29 ++++---- repertory/repertory_test/src/config_test.cpp | 26 ++++---- 4 files changed, 65 insertions(+), 62 deletions(-) diff --git a/repertory/librepertory/include/drives/remote/remote_server_base.hpp b/repertory/librepertory/include/drives/remote/remote_server_base.hpp index 0542e1a4..d4fb3e2d 100644 --- a/repertory/librepertory/include/drives/remote/remote_server_base.hpp +++ b/repertory/librepertory/include/drives/remote/remote_server_base.hpp @@ -52,7 +52,7 @@ public: : config_(config), drive_(drv), mount_location_(std::move(mount_location)), - client_pool_(config.get_remote_client_pool_size()) { + client_pool_(config.get_remote_mount().client_pool_size) { event_system::instance().raise("remote_server_base"); handler_lookup_.insert( {"::winfsp_can_delete", @@ -1357,8 +1357,8 @@ public: }}); packet_server_ = std::make_unique( - config_.get_remote_api_port(), config_.get_remote_encryption_token(), - 10, + config_.get_remote_mount().api_port, + config_.get_remote_mount().encryption_token, 10, [this](const std::string &client_id) { return this->closed_handler(client_id); }, diff --git a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp index 5ebf021e..3d69940e 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp @@ -81,8 +81,8 @@ auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid, struct fuse_file_info * /*file_info*/) -> api_error { #else -auto fuse_drive::chown_impl(std::string api_path, uid_t uid, - gid_t gid) -> api_error { +auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid) + -> api_error { #endif return check_and_perform( api_path, X_OK, [&](api_meta_map &meta) -> api_error { @@ -481,8 +481,8 @@ auto fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st, struct fuse_file_info * /*file_info*/) -> api_error { #else -auto fuse_drive::getattr_impl(std::string api_path, - struct stat *unix_st) -> api_error { +auto fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st) + -> api_error { #endif auto parent = utils::path::get_parent_api_path(api_path); @@ -565,8 +565,8 @@ auto fuse_drive::getxtimes_impl(std::string api_path, struct timespec *bkuptime, #endif // __APPLE__ #if FUSE_USE_VERSION >= 30 -auto fuse_drive::init_impl(struct fuse_conn_info *conn, - struct fuse_config *cfg) -> void * { +auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg) + -> void * { #else void *fuse_drive::init_impl(struct fuse_conn_info *conn) { #endif @@ -612,7 +612,7 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) { eviction_->start(); } - if (config_.get_enable_remote_mount()) { + if (config_.get_remote_mount().enable) { remote_server_ = std::make_unique( config_, *this, get_mount_location()); } @@ -800,8 +800,9 @@ auto fuse_drive::release_impl(std::string /*api_path*/, return api_error::success; } -auto fuse_drive::releasedir_impl( - std::string /*api_path*/, struct fuse_file_info *file_info) -> api_error { +auto fuse_drive::releasedir_impl(std::string /*api_path*/, + struct fuse_file_info *file_info) + -> api_error { auto iter = directory_cache_->get_directory(file_info->fh); if (iter == nullptr) { return api_error::invalid_handle; @@ -819,8 +820,8 @@ auto fuse_drive::rename_directory(const std::string &from_api_path, } auto fuse_drive::rename_file(const std::string &from_api_path, - const std::string &to_api_path, - bool overwrite) -> int { + const std::string &to_api_path, bool overwrite) + -> int { auto res = fm_->rename_file(from_api_path, to_api_path, overwrite); errno = std::abs(utils::from_api_error(res)); return (res == api_error::success) ? 0 : -1; @@ -830,8 +831,8 @@ auto fuse_drive::rename_file(const std::string &from_api_path, auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path, unsigned int /*flags*/) -> api_error { #else -auto fuse_drive::rename_impl(std::string from_api_path, - std::string to_api_path) -> api_error { +auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path) + -> api_error { #endif auto res = check_parent_access(to_api_path, W_OK | X_OK); if (res != api_error::success) { @@ -945,15 +946,15 @@ auto fuse_drive::getxattr_impl(std::string api_path, const char *name, } #else // __APPLE__ auto fuse_drive::getxattr_impl(std::string api_path, const char *name, - char *value, size_t size, - int &attribute_size) -> api_error { + char *value, size_t size, int &attribute_size) + -> api_error { return getxattr_common(api_path, name, value, size, attribute_size, nullptr); } #endif // __APPLE__ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size, - int &required_size, - bool &return_size) -> api_error { + int &required_size, bool &return_size) + -> api_error { auto check_size = (size == 0); auto res = check_parent_access(api_path, X_OK); @@ -993,8 +994,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size, return res; } -auto fuse_drive::removexattr_impl(std::string api_path, - const char *name) -> api_error { +auto fuse_drive::removexattr_impl(std::string api_path, const char *name) + -> api_error { std::string attribute_name; #if defined(__APPLE__) auto res = parse_xattr_parameters(name, 0, attribute_name, api_path); @@ -1022,8 +1023,8 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name, uint32_t position) -> api_error { #else // __APPLE__ auto fuse_drive::setxattr_impl(std::string api_path, const char *name, - const char *value, size_t size, - int flags) -> api_error { + const char *value, size_t size, int flags) + -> api_error { #endif std::string attribute_name; #if defined(__APPLE__) @@ -1101,8 +1102,8 @@ void fuse_drive::set_item_meta(const std::string &api_path, } #if defined(__APPLE__) -auto fuse_drive::setattr_x_impl(std::string api_path, - struct setattr_x *attr) -> api_error { +auto fuse_drive::setattr_x_impl(std::string api_path, struct setattr_x *attr) + -> api_error { bool exists{}; auto res = provider_.is_file(api_path, exists); if (res != api_error::success) { @@ -1156,7 +1157,7 @@ auto fuse_drive::setattr_x_impl(std::string api_path, ts[0].tv_sec = attr->acctime.tv_sec; ts[0].tv_nsec = attr->acctime.tv_nsec; } else { - struct timeval tv {}; + struct timeval tv{}; gettimeofday(&tv, NULL); ts[0].tv_sec = tv.tv_sec; ts[0].tv_nsec = tv.tv_usec * 1000; @@ -1201,8 +1202,9 @@ auto fuse_drive::setattr_x_impl(std::string api_path, return api_error::success; } -auto fuse_drive::setbkuptime_impl( - std::string api_path, const struct timespec *bkuptime) -> api_error { +auto fuse_drive::setbkuptime_impl(std::string api_path, + const struct timespec *bkuptime) + -> api_error { return check_and_perform( api_path, X_OK, [&](api_meta_map &meta) -> api_error { auto nanos = bkuptime->tv_nsec + @@ -1238,8 +1240,8 @@ auto fuse_drive::setvolname_impl(const char * /*volname*/) -> api_error { return api_error::success; } -auto fuse_drive::statfs_x_impl(std::string /*api_path*/, - struct statfs *stbuf) -> api_error { +auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf) + -> api_error { if (statfs(&config_.get_cache_directory()[0], stbuf) != 0) { return api_error::os_error; } @@ -1264,8 +1266,8 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/, return api_error::success; } #else // __APPLE__ -auto fuse_drive::statfs_impl(std::string /*api_path*/, - struct statvfs *stbuf) -> api_error { +auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf) + -> api_error { if (statvfs(config_.get_cache_directory().data(), stbuf) != 0) { return api_error::os_error; } @@ -1345,8 +1347,8 @@ auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2], struct fuse_file_info * /*file_info*/) -> api_error { #else -auto fuse_drive::utimens_impl(std::string api_path, - const struct timespec tv[2]) -> api_error { +auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2]) + -> api_error { #endif api_meta_map meta; auto res = provider_.get_item_meta(api_path, meta); diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index 80e9694e..f07a01d2 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -89,8 +89,8 @@ auto winfsp_drive::handle_error(std::string_view function_name, return ret; } -auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, - PWSTR * /*Argv*/) -> NTSTATUS { +auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/) + -> NTSTATUS { REPERTORY_USES_FUNCTION_NAME(); auto mount_location = utils::string::to_lower( @@ -457,9 +457,10 @@ 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 { auto api_path = utils::path::create_api_path(utils::string::to_utf8(file_name)); @@ -640,7 +641,7 @@ auto winfsp_drive::Mounted(PVOID host) -> NTSTATUS { } auto mount_location = parse_mount_location(file_system_host->MountPoint()); - if (config_.get_enable_remote_mount()) { + if (config_.get_remote_mount().enable) { remote_server_ = std::make_unique( config_, *this, mount_location); } @@ -720,8 +721,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 { REPERTORY_USES_FUNCTION_NAME(); std::string api_path; @@ -827,8 +828,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 { REPERTORY_USES_FUNCTION_NAME(); *bytes_transferred = 0U; @@ -883,8 +884,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 { REPERTORY_USES_FUNCTION_NAME(); std::string api_path; @@ -1046,8 +1047,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 { REPERTORY_USES_FUNCTION_NAME(); std::string api_path; diff --git a/repertory/repertory_test/src/config_test.cpp b/repertory/repertory_test/src/config_test.cpp index 17a1fee9..188728bc 100644 --- a/repertory/repertory_test/src/config_test.cpp +++ b/repertory/repertory_test/src/config_test.cpp @@ -483,19 +483,19 @@ TEST_F(config_test, get_version) { } } -TEST_F(config_test, enable_remote_mount) { - bool original_value{}; - { - app_config config(provider_type::sia, sia_directory); - original_value = config.get_enable_remote_mount(); - config.set_enable_remote_mount(not original_value); - EXPECT_EQ(not original_value, config.get_enable_remote_mount()); - } - { - app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(not original_value, config.get_enable_remote_mount()); - } -} +// TEST_F(config_test, enable_remote_mount) { +// bool original_value{}; +// { +// app_config config(provider_type::sia, sia_directory); +// original_value = config.get_enable_remote_mount(); +// config.set_enable_remote_mount(not original_value); +// EXPECT_EQ(not original_value, config.get_enable_remote_mount()); +// } +// { +// app_config config(provider_type::sia, sia_directory); +// EXPECT_EQ(not original_value, config.get_enable_remote_mount()); +// } +// } // TEST_F(config_test, is_remote_mount) { // bool original_value{};