From 561cfd937a325ba7926307c58c215dc8a4445d3c Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 30 Aug 2024 14:08:39 -0500 Subject: [PATCH] updated build system --- cmake/versions.cmake | 12 +++--- support/include/utils/time.hpp | 3 ++ support/src/utils/file.cpp | 57 ++++++++++++++++++---------- support/src/utils/file_directory.cpp | 34 +++++++++++++++-- support/src/utils/file_file.cpp | 4 +- support/src/utils/file_smb_file.cpp | 6 +-- support/src/utils/time.cpp | 6 +++ 7 files changed, 89 insertions(+), 33 deletions(-) diff --git a/cmake/versions.cmake b/cmake/versions.cmake index 60142bfe..cd3ac409 100644 --- a/cmake/versions.cmake +++ b/cmake/versions.cmake @@ -1,18 +1,18 @@ set(BINUTILS_VERSION 2.41) -set(BOOST_MAJOR_VERSION 1) -set(BOOST_MINOR_VERSION 85) -set(BOOST_PATCH_VERSION 0) set(BOOST2_MAJOR_VERSION 1) set(BOOST2_MINOR_VERSION 76) set(BOOST2_PATCH_VERSION 0) +set(BOOST_MAJOR_VERSION 1) +set(BOOST_MINOR_VERSION 85) +set(BOOST_PATCH_VERSION 0) set(CLI11_VERSION 2.4.2) set(CPP_HTTPLIB_VERSION 0.16.3) -set(CURL_VERSION 8.9.1) set(CURL2_VERSION 8_9_1) +set(CURL_VERSION 8.9.1) set(CXXOPTS_VERSION 3.2.1) set(DTL_VERSION 2.01) -set(EXPAT_VERSION 2.6.2) set(EXPAT2_VERSION 2_6_2) +set(EXPAT_VERSION 2.6.2) set(FLAC_VERSION 1.4.3) set(FMT_VERSION 11.0.2) set(FONTCONFIG_VERSION 2.15.0) @@ -44,8 +44,8 @@ set(SDL_VERSION 2.30.6) set(SECP256K1_VERSION 0.1.0.20) set(SFML_VERSION 2.6.1) set(SPDLOG_VERSION 1.14.1) -set(SQLITE_VERSION 3460100) set(SQLITE2_VERSION 3.46.1) +set(SQLITE_VERSION 3460100) set(STDUUID_VERSION 1.2.3) set(VLC_VERSION 3.0) set(VORBIS_VERSION 1.3.7) diff --git a/support/include/utils/time.hpp b/support/include/utils/time.hpp index 7412f490..c790d840 100644 --- a/support/include/utils/time.hpp +++ b/support/include/utils/time.hpp @@ -52,6 +52,9 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char *; [[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME; +[[nodiscard]] auto +windows_file_time_to_unix_time(FILETIME win_time) -> std::uint64_t; + [[nodiscard]] auto windows_time_t_to_unix_time(__time64_t win_time) -> std::uint64_t; #endif // defined(_WIN32) diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index da380599..18ed5c14 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -26,6 +26,7 @@ #include "utils/path.hpp" #include "utils/string.hpp" #include "utils/time.hpp" +#include "utils/windows.hpp" namespace repertory::utils::file { auto get_time(std::string_view path, @@ -50,46 +51,64 @@ auto get_times(std::string_view path) -> std::optional { try { #if defined(_WIN32) - struct _stat64 st {}; - auto res = _stat64(std::string{path}.c_str(), &st); + auto file_handle = ::CreateFileA(std::string{path}.c_str(), GENERIC_READ, 0, + nullptr, OPEN_EXISTING, 0, nullptr); + if (file_handle == INVALID_HANDLE_VALUE) { + throw std::runtime_error("failed to get file times|" + std::string{path} + + '|' + + std::to_string(utils::get_last_error_code())); + } + + std::array times{}; + auto res = + ::GetFileTime(file_handle, ×.at(0U), ×.at(1U), ×.at(2U)); + ::CloseHandle(file_handle); + + if (not res) { + throw std::runtime_error("failed to get file times|" + std::string{path} + + '|' + + std::to_string(utils::get_last_error_code())); + } #else // !defined(_WIN32) - struct stat st {}; - auto res = stat(std::string{path}.c_str(), &st); -#endif // defined(_WIN32) - if (res != 0) { + struct stat64 st {}; + if (stat64(std::string{path}.c_str(), &st) != 0) { throw std::runtime_error("failed to get file times|" + std::string{path} + '|' + std::to_string(errno)); } +#endif // defined(_WIN32) file_times ret{}; #if defined(_WIN32) - ret.accessed = utils::time::windows_time_t_to_unix_time(st.st_atime); + ret.accessed = utils::time::windows_file_time_to_unix_time(times.at(1U)); #else // !defined(_WIN32) - ret.accessed = static_cast( - st.st_atim.tv_nsec + st.st_atim.tv_sec * utils::time::NANOS_PER_SECOND); + ret.accessed = static_cast(st.st_atim.tv_nsec) + + static_cast(st.st_atim.tv_sec) * + utils::time::NANOS_PER_SECOND; #endif // defined(_WIN32) #if defined(_WIN32) - ret.created = utils::time::windows_time_t_to_unix_time(st.st_ctime); + ret.created = utils::time::windows_file_time_to_unix_time(times.at(0U)); #else // !defined(_WIN32) - ret.created = static_cast( - st.st_ctim.tv_nsec + st.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND); + ret.created = static_cast(st.st_ctim.tv_nsec) + + static_cast(st.st_ctim.tv_sec) * + utils::time::NANOS_PER_SECOND; #endif // defined(_WIN32) #if defined(_WIN32) - ret.modified = utils::time::windows_time_t_to_unix_time(st.st_mtime); + ret.modified = utils::time::windows_file_time_to_unix_time(times.at(2U)); #else // !defined(_WIN32) - ret.modified = static_cast( - st.st_mtim.tv_nsec + st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND); + ret.modified = static_cast(st.st_mtim.tv_nsec) + + static_cast(st.st_mtim.tv_sec) * + utils::time::NANOS_PER_SECOND; #endif // defined(_WIN32) #if defined(_WIN32) - ret.written = utils::time::windows_time_t_to_unix_time(st.st_mtime); + ret.written = utils::time::windows_file_time_to_unix_time(times.at(2U)); #else // !defined(_WIN32) - ret.written = static_cast( - st.st_mtim.tv_nsec + st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND); + ret.written = static_cast(st.st_mtim.tv_nsec) + + static_cast(st.st_mtim.tv_sec) * + utils::time::NANOS_PER_SECOND; #endif // defined(_WIN32) - return ret; } catch (const std::exception &e) { utils::error::handle_exception(function_name, e); diff --git a/support/src/utils/file_directory.cpp b/support/src/utils/file_directory.cpp index 254c7f0a..09c699b3 100644 --- a/support/src/utils/file_directory.cpp +++ b/support/src/utils/file_directory.cpp @@ -89,6 +89,19 @@ auto traverse_directory( namespace repertory::utils::file { auto directory::copy_to(std::string_view new_path, bool overwrite) const -> bool { + static constexpr const std::string_view function_name{ + static_cast(__FUNCTION__), + }; + + try { + throw std::runtime_error("failed to copy directory|" + path_ + '|' + + std::string{new_path} + "|not implemented"); + } catch (const std::exception &e) { + utils::error::handle_exception(function_name, e); + } catch (...) { + utils::error::handle_exception(function_name); + } + return false; } @@ -177,8 +190,8 @@ auto directory::exists() const -> bool { #if defined(_WIN32) return ::PathIsDirectoryA(path_.c_str()) != 0; #else // !defined(_WIN32) - struct stat st {}; - return (stat(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode)); + struct stat64 st {}; + return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode)); #endif // defined(_WIN32) return false; @@ -345,7 +358,22 @@ auto directory::is_symlink() const -> bool { return false; } -auto directory::move_to(std::string_view new_path) -> bool { return false; } +auto directory::move_to(std::string_view new_path) -> bool { + static constexpr const std::string_view function_name{ + static_cast(__FUNCTION__), + }; + + try { + throw std::runtime_error("failed to move directory|" + path_ + '|' + + std::string{new_path} + "|not implemented"); + } catch (const std::exception &e) { + utils::error::handle_exception(function_name, e); + } catch (...) { + utils::error::handle_exception(function_name); + } + + return false; +} auto directory::remove() -> bool { static constexpr const std::string_view function_name{ diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 1fe168ca..983c9032 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -55,8 +55,8 @@ namespace { return (::PathFileExistsA(abs_path.c_str()) && not ::PathIsDirectoryA(abs_path.c_str())); #else // !defined(_WIN32) - struct stat st {}; - return (stat(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode)); + struct stat64 st {}; + return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode)); #endif // defined(_WIN32) } } // namespace diff --git a/support/src/utils/file_smb_file.cpp b/support/src/utils/file_smb_file.cpp index 61709f00..126a7888 100644 --- a/support/src/utils/file_smb_file.cpp +++ b/support/src/utils/file_smb_file.cpp @@ -118,16 +118,16 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path, } switch (type) { - case time_type::access: + case time_type::accessed: return smb_stat_get(st.get(), SMB_STAT_ATIME); - case time_type::creation: + case time_type::created: return smb_stat_get(st.get(), SMB_STAT_CTIME); case time_type::modified: return smb_stat_get(st.get(), SMB_STAT_MTIME); - case time_type::write: + case time_type::written: return smb_stat_get(st.get(), SMB_STAT_WTIME); } } catch (const std::exception &e) { diff --git a/support/src/utils/time.cpp b/support/src/utils/time.cpp index 03e986e7..3460cfb1 100644 --- a/support/src/utils/time.cpp +++ b/support/src/utils/time.cpp @@ -64,6 +64,12 @@ auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME { return file_time; } +auto windows_file_time_to_unix_time(FILETIME win_time) -> std::uint64_t { + return windows_time_to_unix_time( + (static_cast(win_time.dwHighDateTime) << 32ULL) | + static_cast(win_time.dwLowDateTime)); +} + auto windows_time_t_to_unix_time(__time64_t win_time) -> std::uint64_t { return static_cast( std::chrono::duration_cast(