From 81c6875382e4bf3ba98acaae1d0a53802dbd5fa1 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 1 Aug 2025 14:12:27 +0200 Subject: [PATCH] Add macOS support #34 --- cmake/flags.cmake | 13 ++++++--- .../include/providers/base_provider.hpp | 2 +- .../include/providers/s3/s3_provider.hpp | 2 +- .../include/providers/sia/sia_provider.hpp | 2 +- repertory/repertory/src/ui/handlers.cpp | 4 ++- support/src/utils/file.cpp | 28 ++++++++++++++----- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 69e56f11..6b34e9ab 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -35,13 +35,9 @@ list(APPEND PROJECT_CXXFLAGS_LIST -Wcast-align -Wconversion -Wdouble-promotion - -Wduplicated-branches - -Wduplicated-cond -Wextra -Wformat=2 - -Wlogical-op -Wmisleading-indentation - -Wno-useless-cast -Wnon-virtual-dtor -Wnull-dereference -Wold-style-cast @@ -52,6 +48,15 @@ list(APPEND PROJECT_CXXFLAGS_LIST -Wunused ) +if (NOT PROJECT_IS_DARWIN) + list(APPEND PROJECT_CXXFLAGS_LIST + -Wduplicated-branches + -Wduplicated-cond + -Wlogical-op + -Wno-useless-cast + ) +endif() + list(APPEND PROJECT_CFLAGS_LIST ${PROJECT_COMMON_FLAG_LIST} -std=c${CMAKE_C_STANDARD} diff --git a/repertory/librepertory/include/providers/base_provider.hpp b/repertory/librepertory/include/providers/base_provider.hpp index 292e4a58..f698fa3d 100644 --- a/repertory/librepertory/include/providers/base_provider.hpp +++ b/repertory/librepertory/include/providers/base_provider.hpp @@ -29,7 +29,7 @@ namespace repertory { class app_config; class i_file_manager; -class i_http_comm; +struct i_http_comm; class base_provider : public i_provider { private: diff --git a/repertory/librepertory/include/providers/s3/s3_provider.hpp b/repertory/librepertory/include/providers/s3/s3_provider.hpp index 22c5b518..0bde9a7f 100644 --- a/repertory/librepertory/include/providers/s3/s3_provider.hpp +++ b/repertory/librepertory/include/providers/s3/s3_provider.hpp @@ -28,7 +28,7 @@ namespace repertory { class app_config; class i_file_manager; -class i_http_comm; +struct i_http_comm; struct head_object_result; class s3_provider final : public base_provider { diff --git a/repertory/librepertory/include/providers/sia/sia_provider.hpp b/repertory/librepertory/include/providers/sia/sia_provider.hpp index e2897d29..fc564f45 100644 --- a/repertory/librepertory/include/providers/sia/sia_provider.hpp +++ b/repertory/librepertory/include/providers/sia/sia_provider.hpp @@ -28,7 +28,7 @@ namespace repertory { class app_config; class i_file_manager; -class i_http_comm; +struct i_http_comm; class sia_provider : public base_provider { public: diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 47fe87d0..713385ed 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -132,7 +132,9 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server) config_->get_api_port()) .c_str()); #else // error - build fails here + system( + fmt::format(R"(open "http://127.0.0.1:{}/ui")", config_->get_api_port()) + .c_str()); #endif } diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index 83ab0c72..3851fdda 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -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(path.data()), + static_cast(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 { }); } +#if defined(__APPLE__) + ret.accessed = static_cast(st.st_atimespec.tv_nsec) + + static_cast(st.st_atimespec.tv_sec) * + utils::time::NANOS_PER_SECOND; + ret.created = static_cast(st.st_ctimespec.tv_nsec) + + static_cast(st.st_ctimespec.tv_sec) * + utils::time::NANOS_PER_SECOND; + ret.modified = static_cast(st.st_mtimespec.tv_nsec) + + static_cast(st.st_mtimespec.tv_sec) * + utils::time::NANOS_PER_SECOND; + ret.written = static_cast(st.st_mtimespec.tv_nsec) + + static_cast(st.st_mtimespec.tv_sec) * + utils::time::NANOS_PER_SECOND; +#else // !defined(__APPLE__) ret.accessed = static_cast(st.st_atim.tv_nsec) + static_cast(st.st_atim.tv_sec) * utils::time::NANOS_PER_SECOND; @@ -252,7 +267,7 @@ auto get_times(std::string_view path) -> std::optional { ret.written = static_cast(st.st_mtim.tv_nsec) + static_cast(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, " ") &&