Add macOS support #34
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2025-08-01 14:12:27 +02:00
parent 1bbe078799
commit 81c6875382
6 changed files with 36 additions and 15 deletions

View File

@@ -55,7 +55,8 @@ auto change_to_process_directory() -> bool {
std::string path;
path.resize(PATH_MAX + 1);
#if defined(__APPLE__)
proc_pidpath(getpid(), path.c_str(), path.size());
proc_pidpath(getpid(), reinterpret_cast<void *>(path.data()),
static_cast<uint32_t>(path.size()));
#else // !defined(__APPLE__)
auto res = readlink("/proc/self/exe", path.data(), path.size());
if (res == -1) {
@@ -68,7 +69,7 @@ auto change_to_process_directory() -> bool {
}
#endif // defined(__APPLE__)
path = utils::path::get_parent_path(path);
res = chdir(path.c_str());
auto res = chdir(path.c_str());
if (res != 0) {
throw utils::error::create_exception(
function_name, {
@@ -148,7 +149,7 @@ auto get_free_drive_space(std::string_view path)
#if defined(__APPLE__)
struct statvfs st{};
if (statvfs(path.c_str(), &st) != 0) {
if (statvfs(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
"failed to get free disk space",
@@ -240,6 +241,20 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
});
}
#if defined(__APPLE__)
ret.accessed = static_cast<std::uint64_t>(st.st_atimespec.tv_nsec) +
static_cast<std::uint64_t>(st.st_atimespec.tv_sec) *
utils::time::NANOS_PER_SECOND;
ret.created = static_cast<std::uint64_t>(st.st_ctimespec.tv_nsec) +
static_cast<std::uint64_t>(st.st_ctimespec.tv_sec) *
utils::time::NANOS_PER_SECOND;
ret.modified = static_cast<std::uint64_t>(st.st_mtimespec.tv_nsec) +
static_cast<std::uint64_t>(st.st_mtimespec.tv_sec) *
utils::time::NANOS_PER_SECOND;
ret.written = static_cast<std::uint64_t>(st.st_mtimespec.tv_nsec) +
static_cast<std::uint64_t>(st.st_mtimespec.tv_sec) *
utils::time::NANOS_PER_SECOND;
#else // !defined(__APPLE__)
ret.accessed = static_cast<std::uint64_t>(st.st_atim.tv_nsec) +
static_cast<std::uint64_t>(st.st_atim.tv_sec) *
utils::time::NANOS_PER_SECOND;
@@ -252,7 +267,7 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
ret.written = static_cast<std::uint64_t>(st.st_mtim.tv_nsec) +
static_cast<std::uint64_t>(st.st_mtim.tv_sec) *
utils::time::NANOS_PER_SECOND;
#endif // defined(__APPLE__)
#endif // defined(_WIN32)
return ret;
@@ -305,7 +320,7 @@ auto get_total_drive_space(std::string_view path)
#if defined(__APPLE__)
struct statvfs st{};
if (statvfs(path.c_str(), &st) != 0) {
if (statvfs(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
"failed to get total disk space",
@@ -498,8 +513,7 @@ auto write_json_file(std::wstring_view path, const nlohmann::json &data)
#endif // defined(PROJECT_ENABLE_JSON)
#if defined(PROJECT_ENABLE_LIBDSM)
static constexpr auto validate_smb_path =
[](std::string_view path) -> bool {
static constexpr auto validate_smb_path = [](std::string_view path) -> bool {
return (not utils::string::begins_with(path, "///") &&
utils::string::begins_with(path, "//") &&
// not utils::string::contains(path, " ") &&