updated build system and fixes
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2024-08-07 15:01:07 -05:00
parent eaae2fea77
commit 33fa52f5a4
6 changed files with 79 additions and 472 deletions

View File

@ -27,6 +27,55 @@
#include "utils/string.hpp"
namespace repertory::utils::file {
auto file::attach_file(native_handle handle, bool read_only) -> file {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
std::string path;
#if defined(_WIN32)
path.resize(MAX_PATH + 1);
::GetFinalPathNameByHandleA(handle, path.data(),
static_cast<DWORD>(path.size()),
FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
#else // !defined(_WIN32)
source_path.resize(PATH_MAX + 1);
#if defined(__APPLE__)
fcntl(handle, F_GETPATH, source_path.data());
#else // !defined(__APPLE__)
readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(),
source_path.data(), source_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 file{
file_t{ptr},
utils::path::absolute(path),
};
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return {};
}
auto file::open_file(std::filesystem::path path, bool read_only) -> file {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
@ -285,8 +334,8 @@ auto file::truncate(std::size_t size) -> bool {
return ec.value() == 0;
}
auto file::write_(const unsigned char *data, std::size_t to_write,
std::size_t offset, std::size_t *total_written) -> bool {
auto file::write(const unsigned char *data, std::size_t to_write,
std::size_t offset, std::size_t *total_written) -> bool {
#if defined(_WIN32)
recur_mutex_lock lock{mtx_};
#endif // defined(_WIN32)
@ -361,4 +410,11 @@ auto file::size() const -> std::uint64_t {
return 0U;
}
auto file::write(const data_buffer &data, std::uint64_t offset,
std::size_t *total_written) -> bool {
return write(reinterpret_cast<const unsigned char *>(data.data()),
data.size() * sizeof(data_buffer::value_type), offset,
total_written);
}
} // namespace repertory::utils::file