From 52cc40b4cff5df896718d291f81488f30560fa43 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 10 Aug 2024 12:27:47 -0500 Subject: [PATCH] updated build system --- support/include/utils/file.hpp | 12 ++-- support/src/utils/file_file.cpp | 99 +++++++++++++------------- support/src/utils/file_thread_file.cpp | 4 +- support/test/src/utils/file_test.cpp | 28 ++++---- 4 files changed, 73 insertions(+), 70 deletions(-) diff --git a/support/include/utils/file.hpp b/support/include/utils/file.hpp index 5a091a9d..a295accf 100644 --- a/support/include/utils/file.hpp +++ b/support/include/utils/file.hpp @@ -94,9 +94,9 @@ protected: class file final : public i_file { public: - [[nodiscard]] static auto - attach_file(native_handle handle, - bool read_only = false) -> std::unique_ptr; + // [[nodiscard]] static auto + // attach_file(native_handle handle, + // bool read_only = false) -> std::unique_ptr; [[nodiscard]] static auto open_file(std::string_view path, @@ -238,9 +238,9 @@ public: class thread_file final : public i_file { public: - [[nodiscard]] static auto - attach_file(native_handle handle, - bool read_only = false) -> std::unique_ptr; + // [[nodiscard]] static auto + // attach_file(native_handle handle, + // bool read_only = false) -> std::unique_ptr; [[nodiscard]] static auto open_file(std::string_view path, diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 3c484213..9a7b876d 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -27,55 +27,56 @@ #include "utils/string.hpp" namespace repertory::utils::file { -auto file::attach_file(native_handle handle, - bool read_only) -> std::unique_ptr { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - - try { - std::string path; - -#if defined(_WIN32) - path.resize(repertory::max_path_length + 1); - ::GetFinalPathNameByHandleA(handle, path.data(), - static_cast(path.size()), - FILE_NAME_NORMALIZED | VOLUME_NAME_DOS); -#else // !defined(_WIN32) - path.resize(repertory::max_path_length + 1); - -#if defined(__APPLE__) - fcntl(handle, F_GETPATH, source_path.data()); -#else // !defined(__APPLE__) - readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(), path.data(), - path.size()); -#endif // defined(__APPLE__) -#endif // defined(_WIN32) - - path = path.c_str(); - -#if defined(_WIN32) - auto *ptr = _fdopen( - static_cast(_open_osfhandle(reinterpret_cast(handle), - read_only ? _O_RDONLY : _O_RDWR)), - read_only ? "rb" : "rb+"); -#else // !defined(_WIN32) - auto *ptr = fdopen(handle, read_only ? "rb" : "rb+"); -#endif // defined(_WIN32) - - return std::unique_ptr(new file{ - file_t{ptr}, - utils::path::absolute(path), - read_only, - }); - } catch (const std::exception &e) { - utils::error::handle_exception(function_name, e); - } catch (...) { - utils::error::handle_exception(function_name); - } - - return nullptr; -} +// auto file::attach_file(native_handle handle, +// bool read_only) -> std::unique_ptr { +// static constexpr const std::string_view function_name{ +// static_cast(__FUNCTION__), +// }; +// +// try { +// std::string path; +// +// #if defined(_WIN32) +// path.resize(repertory::max_path_length + 1); +// ::GetFinalPathNameByHandleA(handle, path.data(), +// static_cast(path.size()), +// FILE_NAME_NORMALIZED | VOLUME_NAME_DOS); +// #else // !defined(_WIN32) +// path.resize(repertory::max_path_length + 1); +// +// #if defined(__APPLE__) +// fcntl(handle, F_GETPATH, source_path.data()); +// #else // !defined(__APPLE__) +// readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(), +// path.data(), +// path.size()); +// #endif // defined(__APPLE__) +// #endif // defined(_WIN32) +// +// path = path.c_str(); +// +// #if defined(_WIN32) +// auto *ptr = _fdopen( +// static_cast(_open_osfhandle(reinterpret_cast(handle), +// read_only ? _O_RDONLY : _O_RDWR)), +// read_only ? "rb" : "rb+"); +// #else // !defined(_WIN32) +// auto *ptr = fdopen(handle, read_only ? "rb" : "rb+"); +// #endif // defined(_WIN32) +// +// return std::unique_ptr(new file{ +// file_t{ptr}, +// utils::path::absolute(path), +// read_only, +// }); +// } catch (const std::exception &e) { +// utils::error::handle_exception(function_name, e); +// } catch (...) { +// utils::error::handle_exception(function_name); +// } +// +// return nullptr; +// } void file::open() { if (not is_file(path_)) { diff --git a/support/src/utils/file_thread_file.cpp b/support/src/utils/file_thread_file.cpp index 182ab3c8..35eaff17 100644 --- a/support/src/utils/file_thread_file.cpp +++ b/support/src/utils/file_thread_file.cpp @@ -22,8 +22,8 @@ #include "utils/file.hpp" namespace repertory::utils::file { -auto thread_file::attach_file(native_handle handle, - bool read_only) -> std::unique_ptr {} +// auto thread_file::attach_file(native_handle handle, +// bool read_only) -> std::unique_ptr {} auto thread_file::open_file(std::string_view path, bool read_only) -> std::unique_ptr {} diff --git a/support/test/src/utils/file_test.cpp b/support/test/src/utils/file_test.cpp index a3b6b7f3..e380b543 100644 --- a/support/test/src/utils/file_test.cpp +++ b/support/test/src/utils/file_test.cpp @@ -84,19 +84,21 @@ TEST(utils_file, write_fails_for_read_only_file) { } } -TEST(utils_file, can_attach_file) { - for (auto idx = 0U; idx < file_type_count; ++idx) { - auto path = test::generate_test_file_name("utils_file"); - auto file = idx == 0U ? utils::file::file::open_or_create_file(path) - : utils::file::thread_file::open_or_create_file(path); - auto file2 = - idx == 0U ? utils::file::file::attach_file(file->get_handle()) - : utils::file::thread_file::attach_file(file->get_handle()); - EXPECT_TRUE(*file); - EXPECT_TRUE(*file2); - EXPECT_EQ(file->get_path(), file2->get_path()); - } -} +// TEST(utils_file, can_attach_file) { +// for (auto idx = 0U; idx < file_type_count; ++idx) { +// auto path = test::generate_test_file_name("utils_file"); +// auto file = idx == 0U ? utils::file::file::open_or_create_file(path) +// : +// utils::file::thread_file::open_or_create_file(path); +// auto file2 = +// idx == 0U ? utils::file::file::attach_file(file->get_handle()) +// : +// utils::file::thread_file::attach_file(file->get_handle()); +// EXPECT_TRUE(*file); +// EXPECT_TRUE(*file2); +// EXPECT_EQ(file->get_path(), file2->get_path()); +// } +// } #if defined(PROJECT_ENABLE_JSON) TEST(utils_file, read_and_write_json_file) {