This commit is contained in:
2024-08-07 13:12:56 -05:00
parent b4999323da
commit eaae2fea77
6 changed files with 45 additions and 30 deletions

View File

@ -934,7 +934,7 @@ TEST(remote_fuse, all_tests) {
event_system::instance().start(); event_system::instance().start();
#if defined(_WIN32) #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_); mock_winfsp_drive drive(mount_location_);
remote_server server(config, drive, mount_location_); remote_server server(config, drive, mount_location_);
#else #else

View File

@ -491,7 +491,6 @@ TEST(remote_winfsp, all_tests) {
EXPECT_TRUE(found_port); EXPECT_TRUE(found_port);
if (found_port) { if (found_port) {
console_consumer c; console_consumer c;
app_config config(provider_type::remote, win_remote_dir); app_config config(provider_type::remote, win_remote_dir);
config.set_remote_host_name_or_ip("localhost"); config.set_remote_host_name_or_ip("localhost");
config.set_remote_port(port); config.set_remote_port(port);
@ -501,7 +500,7 @@ TEST(remote_winfsp, all_tests) {
event_system::instance().start(); event_system::instance().start();
#if defined(_WIN32) #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_); mock_winfsp_drive drive(mount_location_);
remote_server server(config, drive, mount_location_); remote_server server(config, drive, mount_location_);
#else #else

View File

@ -33,6 +33,7 @@ public:
[[nodiscard]] static auto open_or_create_file(std::filesystem::path path, [[nodiscard]] static auto open_or_create_file(std::filesystem::path path,
bool read_only = false) -> file; bool read_only = false) -> file;
public:
file() noexcept = default; file() noexcept = default;
protected: protected:

View File

@ -28,31 +28,42 @@
namespace repertory::utils::file { namespace repertory::utils::file {
auto file::open_file(std::filesystem::path path, bool read_only) -> file { auto file::open_file(std::filesystem::path path, bool read_only) -> file {
path = utils::path::absolute(path.string()); static constexpr const std::string_view function_name{
if (not is_file(path.string())) { static_cast<const char *>(__FUNCTION__),
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,
}; };
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, auto file::open_or_create_file(std::filesystem::path path,

View File

@ -24,7 +24,7 @@
#if defined(U) #if defined(U)
#undef U #undef U
#endif // defined(U) #endif // defined(U)
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -34,21 +34,23 @@ using namespace ::testing;
#define COMMA , #define COMMA ,
#include "utils/config.hpp"
#include "utils/all.hpp" #include "utils/all.hpp"
namespace repertory::test { namespace repertory::test {
#if defined(PROJECT_ENABLE_LIBSODIUM)
[[nodiscard]] auto create_random_file(std::size_t size) -> utils::file::file; [[nodiscard]] auto create_random_file(std::size_t size) -> utils::file::file;
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
[[nodiscard]] auto [[nodiscard]] auto
generate_test_file_name(std::string_view file_name_no_extension) -> std::string; generate_test_file_name(std::string_view file_name_no_extension) -> std::string;
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
template <typename buffer_t, typename result_t> template <typename buffer_t, typename result_t>
static void decrypt_and_verify(const buffer_t &buffer, std::string_view token, static void decrypt_and_verify(const buffer_t &buffer, std::string_view token,
result_t &result) { result_t &result) {
EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, 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; [[nodiscard]] auto get_test_input_dir() -> std::string;

View File

@ -53,6 +53,7 @@ static auto deleter{std::make_unique<file_deleter>()};
} // namespace } // namespace
namespace repertory::test { namespace repertory::test {
#if defined(PROJECT_ENABLE_LIBSODIUM)
auto create_random_file(std::size_t size) -> utils::file::file { auto create_random_file(std::size_t size) -> utils::file::file {
recur_mutex_lock lock{file_mtx}; recur_mutex_lock lock{file_mtx};
@ -74,6 +75,7 @@ auto create_random_file(std::size_t size) -> utils::file::file {
return file; return file;
} }
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
auto generate_test_file_name(std::string_view file_name_no_extension) auto generate_test_file_name(std::string_view file_name_no_extension)
-> std::string { -> std::string {