diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index 930872d4..8ed80c1c 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -92,14 +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::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_atimespec = + utils::time::windows_time_t_to_unix_time(unix_st.st_atime); + r_stat.st_birthtimespec = + utils::time::windows_time_t_to_unix_time(unix_st.st_ctime); + r_stat.st_ctimespec = + utils::time::windows_time_t_to_unix_time(unix_st.st_ctime); + r_stat.st_mtimespec = + utils::time::windows_time_t_to_unix_time(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 ff07b4ae..47a87e00 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -102,14 +102,10 @@ auto encrypt_provider::create_api_file( buf.st_mtimespec.tv_nsec + (buf.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND); #elif defined(_WIN32) - 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)); + file.accessed_date = utils::time::windows_time_t_to_unix_time(buf.st_atime); + file.changed_date = utils::time::windows_time_t_to_unix_time(buf.st_mtime); + file.creation_date = utils::time::windows_time_t_to_unix_time(buf.st_ctime); + file.modified_date = utils::time::windows_time_t_to_unix_time(buf.st_mtime); #else // !defined(_WIN32) file.changed_date = static_cast( buf.st_mtim.tv_nsec + diff --git a/support/include/utils/time.hpp b/support/include/utils/time.hpp index 05536c2e..7412f490 100644 --- a/support/include/utils/time.hpp +++ b/support/include/utils/time.hpp @@ -51,6 +51,9 @@ void get_local_time_now(struct tm &local_time); 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_time_t_to_unix_time(__time64_t win_time) -> std::uint64_t; #endif // defined(_WIN32) [[nodiscard]] auto diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index ad8380c0..fc61ea5f 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -75,8 +75,7 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { switch (type) { case time_types::access: #if defined(_WIN32) - return utils::time::windows_time_to_unix_time( - static_cast(st.st_atime)); + return utils::time::windows_time_t_to_unix_time(st.st_atime); #else // !defined(_WIN32) return static_cast(st.st_atim.tv_nsec + st.st_atim.tv_sec * @@ -85,8 +84,7 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::creation: #if defined(_WIN32) - return utils::time::windows_time_to_unix_time( - static_cast(st.st_ctime)); + return utils::time::windows_time_t_to_unix_time(st.st_ctime); #else // !defined(_WIN32) return static_cast(st.st_ctim.tv_nsec + st.st_ctim.tv_sec * @@ -95,8 +93,7 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::modified: #if defined(_WIN32) - return utils::time::windows_time_to_unix_time( - static_cast(st.st_mtime)); + return utils::time::windows_time_t_to_unix_time(st.st_mtime); #else // !defined(_WIN32) return static_cast(st.st_mtim.tv_nsec + st.st_mtim.tv_sec * @@ -105,8 +102,7 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t { case time_types::write: #if defined(_WIN32) - return utils::time::windows_time_to_unix_time( - static_cast(st.st_mtime)); + return utils::time::windows_time_t_to_unix_time(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 ecce2a77..c7743abd 100644 --- a/support/src/utils/time.cpp +++ b/support/src/utils/time.cpp @@ -63,6 +63,13 @@ auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME { file_time.dwLowDateTime = win_time & 0xFFFFFFFF; return file_time; } + +auto windows_time_t_to_unix_time(__time32_t win_time) -> std::uint64_t { + return static_cast( + std::chrono::duration_cast( + std::chrono::system_clock::from_time_t(win_time).time_since_epoch()) + .count()); +} #endif // defined(_WIN32) auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {