diff --git a/repertory/repertory_test/src/remote_fuse_test.cpp b/repertory/repertory_test/src/remote_fuse_test.cpp index 54480d92..ac49a8a9 100644 --- a/repertory/repertory_test/src/remote_fuse_test.cpp +++ b/repertory/repertory_test/src/remote_fuse_test.cpp @@ -934,7 +934,7 @@ TEST(remote_fuse, all_tests) { event_system::instance().start(); #if defined(_WIN32) - mount_location_ = std::string(test::get_test_output_dir(), 2); + mount_location_ = test::get_test_output_dir().substr(0, 2); mock_winfsp_drive drive(mount_location_); remote_server server(config, drive, mount_location_); #else diff --git a/repertory/repertory_test/src/remote_winfsp_test.cpp b/repertory/repertory_test/src/remote_winfsp_test.cpp index a76e6774..cf1a5449 100644 --- a/repertory/repertory_test/src/remote_winfsp_test.cpp +++ b/repertory/repertory_test/src/remote_winfsp_test.cpp @@ -491,7 +491,6 @@ TEST(remote_winfsp, all_tests) { EXPECT_TRUE(found_port); if (found_port) { console_consumer c; - app_config config(provider_type::remote, win_remote_dir); config.set_remote_host_name_or_ip("localhost"); config.set_remote_port(port); @@ -501,7 +500,7 @@ TEST(remote_winfsp, all_tests) { event_system::instance().start(); #if defined(_WIN32) - mount_location_ = std::string(test::get_test_output_dir(), 2); + mount_location_ = test::get_test_output_dir().substr(0, 2); mock_winfsp_drive drive(mount_location_); remote_server server(config, drive, mount_location_); #else diff --git a/support/include/utils/file.hpp b/support/include/utils/file.hpp index 7b0ce701..5ce3881f 100644 --- a/support/include/utils/file.hpp +++ b/support/include/utils/file.hpp @@ -33,6 +33,7 @@ public: [[nodiscard]] static auto open_or_create_file(std::filesystem::path path, bool read_only = false) -> file; +public: file() noexcept = default; protected: diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 0723696e..8d6ff6ca 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -28,31 +28,42 @@ namespace repertory::utils::file { auto file::open_file(std::filesystem::path path, bool read_only) -> file { - path = utils::path::absolute(path.string()); - if (not is_file(path.string())) { - throw std::runtime_error("file not found: " + path.string()); - } - - if (not read_only) { -#if defined(_WIN32) - _chmod(path.string().c_str(), 0600U); -#else // !defined(_WIN32) - chmod(path.string().c_str(), 0600U); -#endif // defined(_WIN32) - } - -#if defined(_WIN32) - auto *ptr = - _fsopen(path.string().c_str(), read_only ? "rb" : "rb+", _SH_DENYNO); - std::cout << errno << std::endl; -#else // !defined(_WIN32) - auto *ptr = fopen(path.string().c_str(), read_only ? "rb" : "rb+"); -#endif // defined(_WIN32) - - return file{ - file_t{ptr}, - path, + static constexpr const std::string_view function_name{ + static_cast(__FUNCTION__), }; + + try { + path = utils::path::absolute(path.string()); + if (not is_file(path.string())) { + throw std::runtime_error("file not found: " + path.string()); + } + + if (not read_only) { +#if defined(_WIN32) + _chmod(path.string().c_str(), 0600U); +#else // !defined(_WIN32) + chmod(path.string().c_str(), 0600U); +#endif // defined(_WIN32) + } + +#if defined(_WIN32) + auto *ptr = + _fsopen(path.string().c_str(), read_only ? "rb" : "rb+", _SH_DENYNO); +#else // !defined(_WIN32) + auto *ptr = fopen(path.string().c_str(), read_only ? "rb" : "rb+"); +#endif // defined(_WIN32) + + return file{ + file_t{ptr}, + path, + }; + } catch (const std::exception &e) { + utils::error::handle_exception(function_name, e); + } catch (...) { + utils::error::handle_exception(function_name); + } + + return {}; } auto file::open_or_create_file(std::filesystem::path path, diff --git a/support/test/include/test.hpp b/support/test/include/test.hpp index 8801c978..85645e35 100644 --- a/support/test/include/test.hpp +++ b/support/test/include/test.hpp @@ -24,7 +24,7 @@ #if defined(U) #undef U -#endif // defined(U) +#endif // defined(U) #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -34,21 +34,23 @@ using namespace ::testing; #define COMMA , -#include "utils/config.hpp" - #include "utils/all.hpp" namespace repertory::test { +#if defined(PROJECT_ENABLE_LIBSODIUM) [[nodiscard]] auto create_random_file(std::size_t size) -> utils::file::file; +#endif // defined(PROJECT_ENABLE_LIBSODIUM) [[nodiscard]] auto generate_test_file_name(std::string_view file_name_no_extension) -> std::string; +#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) template static void decrypt_and_verify(const buffer_t &buffer, std::string_view token, result_t &result) { EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, result)); } +#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) [[nodiscard]] auto get_test_input_dir() -> std::string; diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index 5d059d2a..cb7e3651 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -53,6 +53,7 @@ static auto deleter{std::make_unique()}; } // namespace namespace repertory::test { +#if defined(PROJECT_ENABLE_LIBSODIUM) auto create_random_file(std::size_t size) -> utils::file::file { recur_mutex_lock lock{file_mtx}; @@ -74,6 +75,7 @@ auto create_random_file(std::size_t size) -> utils::file::file { return file; } +#endif // defined(PROJECT_ENABLE_LIBSODIUM) auto generate_test_file_name(std::string_view file_name_no_extension) -> std::string {