updated build system
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2024-08-10 12:27:47 -05:00
parent 1e854aa368
commit 52cc40b4cf
4 changed files with 73 additions and 70 deletions

View File

@ -94,9 +94,9 @@ protected:
class file final : public i_file { class file final : public i_file {
public: public:
[[nodiscard]] static auto // [[nodiscard]] static auto
attach_file(native_handle handle, // attach_file(native_handle handle,
bool read_only = false) -> std::unique_ptr<i_file>; // bool read_only = false) -> std::unique_ptr<i_file>;
[[nodiscard]] static auto [[nodiscard]] static auto
open_file(std::string_view path, open_file(std::string_view path,
@ -238,9 +238,9 @@ public:
class thread_file final : public i_file { class thread_file final : public i_file {
public: public:
[[nodiscard]] static auto // [[nodiscard]] static auto
attach_file(native_handle handle, // attach_file(native_handle handle,
bool read_only = false) -> std::unique_ptr<i_file>; // bool read_only = false) -> std::unique_ptr<i_file>;
[[nodiscard]] static auto [[nodiscard]] static auto
open_file(std::string_view path, open_file(std::string_view path,

View File

@ -27,55 +27,56 @@
#include "utils/string.hpp" #include "utils/string.hpp"
namespace repertory::utils::file { namespace repertory::utils::file {
auto file::attach_file(native_handle handle, // auto file::attach_file(native_handle handle,
bool read_only) -> std::unique_ptr<i_file> { // bool read_only) -> std::unique_ptr<i_file> {
static constexpr const std::string_view function_name{ // static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__), // static_cast<const char *>(__FUNCTION__),
}; // };
//
try { // try {
std::string path; // std::string path;
//
#if defined(_WIN32) // #if defined(_WIN32)
path.resize(repertory::max_path_length + 1); // path.resize(repertory::max_path_length + 1);
::GetFinalPathNameByHandleA(handle, path.data(), // ::GetFinalPathNameByHandleA(handle, path.data(),
static_cast<DWORD>(path.size()), // static_cast<DWORD>(path.size()),
FILE_NAME_NORMALIZED | VOLUME_NAME_DOS); // FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
#else // !defined(_WIN32) // #else // !defined(_WIN32)
path.resize(repertory::max_path_length + 1); // path.resize(repertory::max_path_length + 1);
//
#if defined(__APPLE__) // #if defined(__APPLE__)
fcntl(handle, F_GETPATH, source_path.data()); // fcntl(handle, F_GETPATH, source_path.data());
#else // !defined(__APPLE__) // #else // !defined(__APPLE__)
readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(), path.data(), // readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(),
path.size()); // path.data(),
#endif // defined(__APPLE__) // path.size());
#endif // defined(_WIN32) // #endif // defined(__APPLE__)
// #endif // defined(_WIN32)
path = path.c_str(); //
// path = path.c_str();
#if defined(_WIN32) //
auto *ptr = _fdopen( // #if defined(_WIN32)
static_cast<int>(_open_osfhandle(reinterpret_cast<intptr_t>(handle), // auto *ptr = _fdopen(
read_only ? _O_RDONLY : _O_RDWR)), // static_cast<int>(_open_osfhandle(reinterpret_cast<intptr_t>(handle),
read_only ? "rb" : "rb+"); // read_only ? _O_RDONLY : _O_RDWR)),
#else // !defined(_WIN32) // read_only ? "rb" : "rb+");
auto *ptr = fdopen(handle, read_only ? "rb" : "rb+"); // #else // !defined(_WIN32)
#endif // defined(_WIN32) // auto *ptr = fdopen(handle, read_only ? "rb" : "rb+");
// #endif // defined(_WIN32)
return std::unique_ptr<i_file>(new file{ //
file_t{ptr}, // return std::unique_ptr<i_file>(new file{
utils::path::absolute(path), // file_t{ptr},
read_only, // utils::path::absolute(path),
}); // read_only,
} catch (const std::exception &e) { // });
utils::error::handle_exception(function_name, e); // } catch (const std::exception &e) {
} catch (...) { // utils::error::handle_exception(function_name, e);
utils::error::handle_exception(function_name); // } catch (...) {
} // utils::error::handle_exception(function_name);
// }
return nullptr; //
} // return nullptr;
// }
void file::open() { void file::open() {
if (not is_file(path_)) { if (not is_file(path_)) {

View File

@ -22,8 +22,8 @@
#include "utils/file.hpp" #include "utils/file.hpp"
namespace repertory::utils::file { namespace repertory::utils::file {
auto thread_file::attach_file(native_handle handle, // auto thread_file::attach_file(native_handle handle,
bool read_only) -> std::unique_ptr<i_file> {} // bool read_only) -> std::unique_ptr<i_file> {}
auto thread_file::open_file(std::string_view path, auto thread_file::open_file(std::string_view path,
bool read_only) -> std::unique_ptr<i_file> {} bool read_only) -> std::unique_ptr<i_file> {}

View File

@ -84,19 +84,21 @@ TEST(utils_file, write_fails_for_read_only_file) {
} }
} }
TEST(utils_file, can_attach_file) { // TEST(utils_file, can_attach_file) {
for (auto idx = 0U; idx < file_type_count; ++idx) { // for (auto idx = 0U; idx < file_type_count; ++idx) {
auto path = test::generate_test_file_name("utils_file"); // auto path = test::generate_test_file_name("utils_file");
auto file = idx == 0U ? utils::file::file::open_or_create_file(path) // auto file = idx == 0U ? utils::file::file::open_or_create_file(path)
: utils::file::thread_file::open_or_create_file(path); // :
auto file2 = // utils::file::thread_file::open_or_create_file(path);
idx == 0U ? utils::file::file::attach_file(file->get_handle()) // auto file2 =
: utils::file::thread_file::attach_file(file->get_handle()); // idx == 0U ? utils::file::file::attach_file(file->get_handle())
EXPECT_TRUE(*file); // :
EXPECT_TRUE(*file2); // utils::file::thread_file::attach_file(file->get_handle());
EXPECT_EQ(file->get_path(), file2->get_path()); // EXPECT_TRUE(*file);
} // EXPECT_TRUE(*file2);
} // EXPECT_EQ(file->get_path(), file2->get_path());
// }
// }
#if defined(PROJECT_ENABLE_JSON) #if defined(PROJECT_ENABLE_JSON)
TEST(utils_file, read_and_write_json_file) { TEST(utils_file, read_and_write_json_file) {