diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp index 2331079c..e54ee2d5 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp @@ -314,7 +314,7 @@ void remote_fuse_drive::populate_stat(const remote::stat &r_stat, unix_st.st_mtimespec.tv_sec = r_stat.st_mtimespec / NANOS_PER_SECOND; unix_st.st_flags = r_stat.st_flags; -#else +#else // !defined(__APPLE__) unix_st.st_blksize = 4096; unix_st.st_atim.tv_nsec = @@ -331,7 +331,8 @@ void remote_fuse_drive::populate_stat(const remote::stat &r_stat, static_cast(r_stat.st_mtimespec % NANOS_PER_SECOND); unix_st.st_mtim.tv_sec = static_cast(r_stat.st_mtimespec / NANOS_PER_SECOND); -#endif +#endif // defined(__APPLE__) + if (not directory) { const auto block_size_stat = static_cast(512U); const auto block_size = static_cast(4096U); diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index f59f4b1a..54c3ae78 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -92,10 +92,14 @@ void remote_server::populate_stat(const char *path, bool directory, directory ? 2 + drive_.get_directory_item_count( utils::path::create_api_path(path)) : 1); - r_stat.st_atimespec = utils::time::time64_to_unix_time(unix_st.st_atime); - r_stat.st_birthtimespec = utils::time::time64_to_unix_time(unix_st.st_ctime); - r_stat.st_ctimespec = utils::time::time64_to_unix_time(unix_st.st_ctime); - r_stat.st_mtimespec = utils::time::time64_to_unix_time(unix_st.st_mtime); + r_stat.st_atimespec = utils::time::windows_time_to_unix_time( + static_cast(unix_st.st_atime)); + r_stat.st_birthtimespec = utils::time::windows_time_to_unix_time( + static_cast(unix_st.st_ctime)); + r_stat.st_ctimespec = utils::time::windows_time_to_unix_time( + static_cast(unix_st.st_ctime)); + r_stat.st_mtimespec = utils::time::windows_time_to_unix_time( + static_cast(unix_st.st_mtime)); r_stat.st_size = static_cast(unix_st.st_size); r_stat.st_mode = unix_st.st_mode; } diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index b2b6b260..0c473c12 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -99,26 +99,15 @@ auto encrypt_provider::create_api_file( file.modified_date = buf.st_mtimespec.tv_nsec + (buf.st_mtimespec.tv_sec * NANOS_PER_SECOND); #elif defined(_WIN32) - auto ft = utils::time::unix_time_to_filetime( - utils::time::time64_to_unix_time(buf.st_atime)); - file.accessed_date = - (static_cast(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; - - ft = utils::time::unix_time_to_filetime( - utils::time::time64_to_unix_time(buf.st_mtime)); - file.changed_date = - (static_cast(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; - - ft = utils::time::unix_time_to_filetime( - utils::time::time64_to_unix_time(buf.st_ctime)); - file.creation_date = - (static_cast(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; - - ft = utils::time::unix_time_to_filetime( - utils::time::time64_to_unix_time(buf.st_mtime)); - file.modified_date = - (static_cast(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; -#else + file.accessed_date = utils::time::windows_time_to_unix_time( + static_cast(buf.st_atime)); + file.changed_date = utils::time::windows_time_to_unix_time( + static_cast(buf.st_mtime)); + file.creation_date = utils::time::windows_time_to_unix_time( + static_cast(buf.st_ctime)); + file.modified_date = utils::time::windows_time_to_unix_time( + static_cast(buf.st_mtime)); +#else // !defined(_WIN32) file.changed_date = static_cast( buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); file.accessed_date = static_cast( @@ -127,7 +116,7 @@ auto encrypt_provider::create_api_file( buf.st_ctim.tv_nsec + (buf.st_ctim.tv_sec * NANOS_PER_SECOND)); file.modified_date = static_cast( buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); -#endif +#endif // defined(__APPLE__) return file; } diff --git a/repertory/librepertory/src/utils/file_utils.cpp b/repertory/librepertory/src/utils/file_utils.cpp index 8f3ba987..64c7746f 100644 --- a/repertory/librepertory/src/utils/file_utils.cpp +++ b/repertory/librepertory/src/utils/file_utils.cpp @@ -245,7 +245,8 @@ auto get_accessed_time(const std::string &path, #if defined(_WIN32) struct _stat64 st {}; if (_stat64(path.c_str(), &st) != -1) { - accessed = static_cast(st.st_atime); + accessed = time::windows_time_to_unix_time( + static_cast(st.st_atime)); #else struct stat st {}; if (stat(path.c_str(), &st) != -1) { @@ -270,7 +271,8 @@ auto get_modified_time(const std::string &path, #if defined(_WIN32) struct _stat64 st {}; if (_stat64(path.c_str(), &st) != -1) { - modified = static_cast(st.st_mtime); + modified = time::windows_time_to_unix_time( + static_cast(st.st_mtime)); #else struct stat st {}; if (stat(path.c_str(), &st) != -1) { @@ -293,18 +295,12 @@ auto is_modified_date_older_than(const std::string &path, auto ret = false; std::uint64_t modified{}; if (get_modified_time(path, modified)) { - const auto seconds = - std::chrono::duration_cast(hours); -#if defined(_WIN32) - return (std::chrono::system_clock::from_time_t( - static_cast(modified)) + - seconds) < std::chrono::system_clock::now(); -#else + auto seconds = std::chrono::duration_cast(hours); return (modified + static_cast(seconds.count() * NANOS_PER_SECOND)) < utils::time::get_time_now(); -#endif } + return ret; } diff --git a/repertory/librepertory/src/utils/utils.cpp b/repertory/librepertory/src/utils/utils.cpp index 3530e127..72a1b855 100644 --- a/repertory/librepertory/src/utils/utils.cpp +++ b/repertory/librepertory/src/utils/utils.cpp @@ -22,15 +22,8 @@ #include "utils/utils.hpp" #include "app_config.hpp" -#include "events/event_system.hpp" -#include "events/events.hpp" -#include "providers/i_provider.hpp" -#include "types/startup_exception.hpp" -#include "utils/com_init_wrapper.hpp" #include "utils/common.hpp" -#include "utils/path.hpp" #include "utils/string.hpp" -#include "utils/time.hpp" namespace repertory::utils { void calculate_allocation_size(bool directory, std::uint64_t file_size, diff --git a/support/include/utils/time.hpp b/support/include/utils/time.hpp index 640e1751..e5460e67 100644 --- a/support/include/utils/time.hpp +++ b/support/include/utils/time.hpp @@ -25,7 +25,7 @@ #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}; @@ -55,8 +55,6 @@ void get_local_time_now(struct tm &local_time); #if defined(_WIN32) auto strptime(const char *s, const char *f, struct tm *tm) -> const char *; -[[nodiscard]] auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t; - [[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME; #endif // defined(_WIN32) diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index 85f959b3..ad8380c0 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -75,7 +75,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { switch (type) { case time_types::access: #if defined(_WIN32) - return static_cast(st.st_atime); + return utils::time::windows_time_to_unix_time( + static_cast(st.st_atime)); #else // !defined(_WIN32) return static_cast(st.st_atim.tv_nsec + st.st_atim.tv_sec * @@ -84,7 +85,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::creation: #if defined(_WIN32) - return static_cast(st.st_ctime); + return utils::time::windows_time_to_unix_time( + static_cast(st.st_ctime)); #else // !defined(_WIN32) return static_cast(st.st_ctim.tv_nsec + st.st_ctim.tv_sec * @@ -93,7 +95,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::modified: #if defined(_WIN32) - return static_cast(st.st_mtime); + return utils::time::windows_time_to_unix_time( + static_cast(st.st_mtime)); #else // !defined(_WIN32) return static_cast(st.st_mtim.tv_nsec + st.st_mtim.tv_sec * @@ -102,7 +105,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::write: #if defined(_WIN32) - return static_cast(st.st_mtime); + return utils::time::windows_time_to_unix_time( + static_cast(st.st_mtime)); #else // !defined(_WIN32) return static_cast(st.st_mtim.tv_nsec + st.st_mtim.tv_sec * diff --git a/support/src/utils/time.cpp b/support/src/utils/time.cpp index cc11ca04..c706d7cc 100644 --- a/support/src/utils/time.cpp +++ b/support/src/utils/time.cpp @@ -66,10 +66,6 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char * { return reinterpret_cast(s + input.tellg()); } -auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t { - return static_cast(time * NANOS_PER_SECOND); -} - // 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 =