This commit is contained in:
2024-08-29 13:09:32 -05:00
parent 82bb90f66d
commit 643486b2c4
5 changed files with 26 additions and 24 deletions

View File

@ -92,14 +92,14 @@ void remote_server::populate_stat(const char *path, bool directory,
directory ? 2 + drive_.get_directory_item_count( directory ? 2 + drive_.get_directory_item_count(
utils::path::create_api_path(path)) utils::path::create_api_path(path))
: 1); : 1);
r_stat.st_atimespec = utils::time::windows_time_to_unix_time( r_stat.st_atimespec =
static_cast<std::uint64_t>(unix_st.st_atime)); utils::time::windows_time_t_to_unix_time(unix_st.st_atime);
r_stat.st_birthtimespec = utils::time::windows_time_to_unix_time( r_stat.st_birthtimespec =
static_cast<std::uint64_t>(unix_st.st_ctime)); utils::time::windows_time_t_to_unix_time(unix_st.st_ctime);
r_stat.st_ctimespec = utils::time::windows_time_to_unix_time( r_stat.st_ctimespec =
static_cast<std::uint64_t>(unix_st.st_ctime)); utils::time::windows_time_t_to_unix_time(unix_st.st_ctime);
r_stat.st_mtimespec = utils::time::windows_time_to_unix_time( r_stat.st_mtimespec =
static_cast<std::uint64_t>(unix_st.st_mtime)); utils::time::windows_time_t_to_unix_time(unix_st.st_mtime);
r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size); r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size);
r_stat.st_mode = unix_st.st_mode; r_stat.st_mode = unix_st.st_mode;
} }

View File

@ -102,14 +102,10 @@ auto encrypt_provider::create_api_file(
buf.st_mtimespec.tv_nsec + buf.st_mtimespec.tv_nsec +
(buf.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND); (buf.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
#elif defined(_WIN32) #elif defined(_WIN32)
file.accessed_date = utils::time::windows_time_to_unix_time( file.accessed_date = utils::time::windows_time_t_to_unix_time(buf.st_atime);
static_cast<std::uint64_t>(buf.st_atime)); file.changed_date = utils::time::windows_time_t_to_unix_time(buf.st_mtime);
file.changed_date = utils::time::windows_time_to_unix_time( file.creation_date = utils::time::windows_time_t_to_unix_time(buf.st_ctime);
static_cast<std::uint64_t>(buf.st_mtime)); file.modified_date = utils::time::windows_time_t_to_unix_time(buf.st_mtime);
file.creation_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_ctime));
file.modified_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_mtime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
file.changed_date = static_cast<std::uint64_t>( file.changed_date = static_cast<std::uint64_t>(
buf.st_mtim.tv_nsec + buf.st_mtim.tv_nsec +

View File

@ -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 *; 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 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) #endif // defined(_WIN32)
[[nodiscard]] auto [[nodiscard]] auto

View File

@ -75,8 +75,7 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
switch (type) { switch (type) {
case time_types::access: case time_types::access:
#if defined(_WIN32) #if defined(_WIN32)
return utils::time::windows_time_to_unix_time( return utils::time::windows_time_t_to_unix_time(st.st_atime);
static_cast<std::uint64_t>(st.st_atime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_atim.tv_nsec + return static_cast<std::uint64_t>(st.st_atim.tv_nsec +
st.st_atim.tv_sec * 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: case time_types::creation:
#if defined(_WIN32) #if defined(_WIN32)
return utils::time::windows_time_to_unix_time( return utils::time::windows_time_t_to_unix_time(st.st_ctime);
static_cast<std::uint64_t>(st.st_ctime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_ctim.tv_nsec + return static_cast<std::uint64_t>(st.st_ctim.tv_nsec +
st.st_ctim.tv_sec * 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: case time_types::modified:
#if defined(_WIN32) #if defined(_WIN32)
return utils::time::windows_time_to_unix_time( return utils::time::windows_time_t_to_unix_time(st.st_mtime);
static_cast<std::uint64_t>(st.st_mtime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec + return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
st.st_mtim.tv_sec * 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: case time_types::write:
#if defined(_WIN32) #if defined(_WIN32)
return utils::time::windows_time_to_unix_time( return utils::time::windows_time_t_to_unix_time(st.st_mtime);
static_cast<std::uint64_t>(st.st_mtime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec + return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
st.st_mtim.tv_sec * st.st_mtim.tv_sec *

View File

@ -63,6 +63,13 @@ auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
file_time.dwLowDateTime = win_time & 0xFFFFFFFF; file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
return file_time; return file_time;
} }
auto windows_time_t_to_unix_time(__time32_t win_time) -> std::uint64_t {
return static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::from_time_t(win_time).time_since_epoch())
.count());
}
#endif // defined(_WIN32) #endif // defined(_WIN32)
auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t { auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {