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 {
public:
[[nodiscard]] static auto
attach_file(native_handle handle,
bool read_only = false) -> std::unique_ptr<i_file>;
// [[nodiscard]] static auto
// attach_file(native_handle handle,
// bool read_only = false) -> std::unique_ptr<i_file>;
[[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<i_file>;
// [[nodiscard]] static auto
// attach_file(native_handle handle,
// bool read_only = false) -> std::unique_ptr<i_file>;
[[nodiscard]] static auto
open_file(std::string_view path,

View File

@ -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<i_file> {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
std::string path;
#if defined(_WIN32)
path.resize(repertory::max_path_length + 1);
::GetFinalPathNameByHandleA(handle, path.data(),
static_cast<DWORD>(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<int>(_open_osfhandle(reinterpret_cast<intptr_t>(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<i_file>(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<i_file> {
// static constexpr const std::string_view function_name{
// static_cast<const char *>(__FUNCTION__),
// };
//
// try {
// std::string path;
//
// #if defined(_WIN32)
// path.resize(repertory::max_path_length + 1);
// ::GetFinalPathNameByHandleA(handle, path.data(),
// static_cast<DWORD>(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<int>(_open_osfhandle(reinterpret_cast<intptr_t>(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<i_file>(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_)) {

View File

@ -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<i_file> {}
// auto thread_file::attach_file(native_handle handle,
// bool read_only) -> std::unique_ptr<i_file> {}
auto thread_file::open_file(std::string_view path,
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) {
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) {