From d4f0431cd5508d2bed9f629e860b5467e8559a23 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 23 Aug 2024 12:01:46 -0500 Subject: [PATCH] updated build system --- .../include/providers/s3/s3_provider.hpp | 4 ++ .../include/utils/unix/unix_utils.hpp | 6 --- .../drives/fuse/remotefuse/remote_server.cpp | 38 +++++++++++-------- .../src/providers/s3/s3_provider.cpp | 18 +++++++++ .../src/utils/unix/unix_utils.cpp | 8 ---- .../repertory_test/src/remote_winfsp_test.cpp | 3 +- support/include/utils/time.hpp | 10 ++++- support/src/utils/time.cpp | 24 ++++++++---- 8 files changed, 71 insertions(+), 40 deletions(-) diff --git a/repertory/librepertory/include/providers/s3/s3_provider.hpp b/repertory/librepertory/include/providers/s3/s3_provider.hpp index 2a770fbb..77ceab48 100644 --- a/repertory/librepertory/include/providers/s3/s3_provider.hpp +++ b/repertory/librepertory/include/providers/s3/s3_provider.hpp @@ -46,6 +46,10 @@ public: auto operator=(const s3_provider &) -> s3_provider & = delete; auto operator=(s3_provider &&) -> s3_provider & = delete; +public: + [[nodiscard]] static auto + convert_api_date(std::string_view date) -> std::uint64_t; + private: [[nodiscard]] auto add_if_not_found(api_file &file, diff --git a/repertory/librepertory/include/utils/unix/unix_utils.hpp b/repertory/librepertory/include/utils/unix/unix_utils.hpp index 1d19242c..00e3d3d6 100644 --- a/repertory/librepertory/include/utils/unix/unix_utils.hpp +++ b/repertory/librepertory/include/utils/unix/unix_utils.hpp @@ -43,15 +43,9 @@ inline const std::array attribute_namespaces = { [[nodiscard]] auto unix_error_to_windows(int err) -> std::uint32_t; -[[nodiscard]] auto -unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64; - void windows_create_to_unix(const UINT32 &create_options, const UINT32 &granted_access, std::uint32_t &flags, remote::file_mode &mode); - -[[nodiscard]] auto -windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time; } // namespace repertory::utils #endif // !_WIN32 diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 4d168ad6..1162bfe7 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -125,18 +125,18 @@ void remote_server::populate_file_info(const std::string &api_path, file_info.AllocationSize = utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) * WINFSP_ALLOCATION_UNIT; - file_info.ChangeTime = utils::unix_time_to_windows_time( + file_info.ChangeTime = utils::time::unix_time_to_windows_time( utils::string::to_uint64(empty_as_zero(meta[META_MODIFIED]))); - file_info.CreationTime = utils::unix_time_to_windows_time( + file_info.CreationTime = utils::time::unix_time_to_windows_time( utils::string::to_uint64(empty_as_zero(meta[META_CREATION]))); file_info.EaSize = 0; file_info.FileAttributes = attributes; file_info.FileSize = file_size; file_info.HardLinks = 0; file_info.IndexNumber = 0; - file_info.LastAccessTime = utils::unix_time_to_windows_time( + file_info.LastAccessTime = utils::time::unix_time_to_windows_time( utils::string::to_uint64(empty_as_zero(meta[META_ACCESSED]))); - file_info.LastWriteTime = utils::unix_time_to_windows_time( + file_info.LastWriteTime = utils::time::unix_time_to_windows_time( utils::string::to_uint64(empty_as_zero(meta[META_WRITTEN]))); if (meta[META_WRITTEN].empty() || (meta[META_WRITTEN] == "0") || (meta[META_WRITTEN] == "116444736000000000")) { @@ -1543,25 +1543,28 @@ auto remote_server::winfsp_set_basic_info( if ((creation_time != 0U) && (creation_time != max_time)) { drive_.set_item_meta( api_path, META_CREATION, - std::to_string(utils::windows_time_to_unix_time(creation_time))); + std::to_string( + utils::time::windows_time_to_unix_time(creation_time))); } if ((last_access_time != 0U) && (last_access_time != max_time)) { drive_.set_item_meta( api_path, META_ACCESSED, - std::to_string(utils::windows_time_to_unix_time(last_access_time))); + std::to_string( + utils::time::windows_time_to_unix_time(last_access_time))); } if ((last_write_time != 0U) && (last_write_time != max_time)) { drive_.set_item_meta( api_path, META_WRITTEN, - std::to_string(utils::windows_time_to_unix_time(last_write_time))); + std::to_string( + utils::time::windows_time_to_unix_time(last_write_time))); } if ((change_time != 0U) && (change_time != max_time)) { drive_.set_item_meta( api_path, META_MODIFIED, - std::to_string(utils::windows_time_to_unix_time(change_time))); + std::to_string(utils::time::windows_time_to_unix_time(change_time))); } ret = populate_file_info(api_path, *file_info); @@ -1746,12 +1749,15 @@ auto remote_server::json_release_directory_snapshot( auto remote_server::update_to_windows_format(json &item) -> json & { const auto api_path = item["path"].get(); - item["meta"][META_MODIFIED] = std::to_string(utils::unix_time_to_windows_time( - utils::string::to_uint64(empty_as_zero(item["meta"][META_MODIFIED])))); - item["meta"][META_CREATION] = std::to_string(utils::unix_time_to_windows_time( - utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION])))); - item["meta"][META_ACCESSED] = std::to_string(utils::unix_time_to_windows_time( - utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED])))); + item["meta"][META_MODIFIED] = std::to_string( + utils::time::unix_time_to_windows_time(utils::string::to_uint64( + empty_as_zero(item["meta"][META_MODIFIED])))); + item["meta"][META_CREATION] = std::to_string( + utils::time::unix_time_to_windows_time(utils::string::to_uint64( + empty_as_zero(item["meta"][META_CREATION])))); + item["meta"][META_ACCESSED] = std::to_string( + utils::time::unix_time_to_windows_time(utils::string::to_uint64( + empty_as_zero(item["meta"][META_ACCESSED])))); if (item["meta"][META_ATTRIBUTES].empty()) { item["meta"][META_ATTRIBUTES] = item["directory"].get() ? std::to_string(FILE_ATTRIBUTE_DIRECTORY) @@ -1766,11 +1772,11 @@ auto remote_server::update_to_windows_format(json &item) -> json & { drive_.set_item_meta(api_path, META_WRITTEN, item["meta"][META_MODIFIED].get()); item["meta"][META_WRITTEN] = std::to_string( - utils::unix_time_to_windows_time(utils::string::to_uint64( + utils::time::unix_time_to_windows_time(utils::string::to_uint64( empty_as_zero(item["meta"][META_MODIFIED])))); } else { item["meta"][META_WRITTEN] = std::to_string( - utils::unix_time_to_windows_time(utils::string::to_uint64( + utils::time::unix_time_to_windows_time(utils::string::to_uint64( empty_as_zero(item["meta"][META_WRITTEN])))); } return item; diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 50d36da0..91a3b742 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -60,6 +60,24 @@ auto s3_provider::add_if_not_found( return api_error::success; } +auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t { + // 2009-10-12T17:50:30.000Z + auto date_parts = utils::string::split(date, '.', true); + auto date_time = date_parts.at(0U); + auto nanos = utils::string::to_uint64( + utils::string::split(date_parts.at(1U), 'Z', true).at(0U)); + + struct tm tm1 {}; +#if defined(_WIN32) + utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1); +#else + strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1); +#endif + + return nanos + (static_cast(mktime(&tm1)) * + utils::time::NANOS_PER_SECOND); +} + auto s3_provider::create_directory_impl(const std::string &api_path, api_meta_map &meta) -> api_error { static constexpr const std::string_view function_name{ diff --git a/repertory/librepertory/src/utils/unix/unix_utils.cpp b/repertory/librepertory/src/utils/unix/unix_utils.cpp index 428ae4e8..60ac4f75 100644 --- a/repertory/librepertory/src/utils/unix/unix_utils.cpp +++ b/repertory/librepertory/src/utils/unix/unix_utils.cpp @@ -201,10 +201,6 @@ auto unix_error_to_windows(int err) -> std::uint32_t { } } -auto unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64 { - return (file_time / 100ULL) + 116444736000000000ULL; -} - void windows_create_to_unix(const UINT32 &create_options, const UINT32 &granted_access, std::uint32_t &flags, remote::file_mode &mode) { @@ -221,10 +217,6 @@ void windows_create_to_unix(const UINT32 &create_options, mode |= (S_IXUSR); } } - -auto windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time { - return (win_time - 116444736000000000ULL) * 100ULL; -} } // namespace repertory::utils #endif // !_WIN32 diff --git a/repertory/repertory_test/src/remote_winfsp_test.cpp b/repertory/repertory_test/src/remote_winfsp_test.cpp index 0ce6ff52..2c0ab2ed 100644 --- a/repertory/repertory_test/src/remote_winfsp_test.cpp +++ b/repertory/repertory_test/src/remote_winfsp_test.cpp @@ -33,6 +33,7 @@ #include "platform/platform.hpp" #include "types/repertory.hpp" #include "utils/common.hpp" +#include "utils/time.hpp" using namespace repertory; using namespace repertory::remote_winfsp; @@ -429,7 +430,7 @@ static void set_basic_info_test(remote_client &client) { const auto change_time = last_write_time; #else const auto creation_time = - utils::unix_time_to_windows_time(utils::time::get_time_now()); + utils::time::unix_time_to_windows_time(utils::time::get_time_now()); const auto last_access_time = creation_time + 1; const auto last_write_time = creation_time + 2; const auto change_time = last_write_time; diff --git a/support/include/utils/time.hpp b/support/include/utils/time.hpp index 35b77f88..a5469e4a 100644 --- a/support/include/utils/time.hpp +++ b/support/include/utils/time.hpp @@ -25,7 +25,9 @@ #include "utils/config.hpp" namespace repertory::utils::time { -inline constexpr const auto NANOS_PER_SECOND = 1000000000L; +inline constexpr const auto NANOS_PER_SECOND = 1000000000ULL; +inline constexpr const auto WIN32_TIME_CONVERSION{116444736000000000ULL}; +inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL}; #if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT) [[nodiscard]] inline auto convert_to_utc(time_t time) -> std::time_t { @@ -57,6 +59,12 @@ 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; #endif // defined(_WIN32) + +[[nodiscard]] auto +unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t; + +[[nodiscard]] auto +windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t; } // namespace repertory::utils::time #endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_ diff --git a/support/src/utils/time.cpp b/support/src/utils/time.cpp index b8fb0c7d..cc11ca04 100644 --- a/support/src/utils/time.cpp +++ b/support/src/utils/time.cpp @@ -28,9 +28,9 @@ auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t { LARGE_INTEGER date{}; date.HighPart = static_cast(file_time.dwHighDateTime); date.LowPart = file_time.dwLowDateTime; - date.QuadPart -= 116444736000000000LL; + date.QuadPart -= WIN32_TIME_CONVERSION; - return static_cast(date.QuadPart) * 100ULL; + return static_cast(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK; } #endif // defined(_WIN32) @@ -47,11 +47,10 @@ void get_local_time_now(struct tm &local_time) { } auto get_time_now() -> std::uint64_t { -#if defined(_WIN32) - return static_cast(_time64(nullptr)); -#else // !defined(_WIN32) - return static_cast(time(nullptr)); -#endif // defined(_WIN32) + return static_cast( + std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count()); } #if defined(_WIN32) @@ -73,11 +72,20 @@ auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t { // https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME { - auto win_time = (unix_time / 100ULL) + 116444736000000000ULL; + auto win_time = + (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION; FILETIME file_time{}; file_time.dwHighDateTime = static_cast(win_time >> 32U); file_time.dwLowDateTime = win_time & 0xFFFFFFFF; return file_time; } #endif // defined(_WIN32) + +auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t { + return (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION; +} + +auto windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t { + return (win_time - WIN32_TIME_CONVERSION) * WIN32_TIME_NANOS_PER_TICK; +} } // namespace repertory::utils::time