From b0be2feebc89b7bfc4d11c3f501541d2d713b8ee Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 26 Jan 2018 16:01:40 +0300 Subject: [PATCH] Fix file stat on Windows. GitOrigin-RevId: 2ca2bb1605af4e25f24d6c06c0aae5ffb8fe09e8 --- td/telegram/cli.cpp | 2 ++ tdutils/td/utils/port/FileFd.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 8adaa2fe..a7634175 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1528,6 +1528,8 @@ class CliClient final : public Actor { send_request(make_tl_object( 10000000, -1, -1, 0, std::vector>(), as_chat_ids(chat_ids, ','), as_chat_ids(exclude_chat_ids, ','), to_integer(chat_ids_limit))); + } else if (op == "clean_storage_default") { + send_request(make_tl_object()); } else if (op == "clean_storage") { std::vector> types; types.push_back(make_tl_object()); diff --git a/tdutils/td/utils/port/FileFd.cpp b/tdutils/td/utils/port/FileFd.cpp index aad611e0..d82131e0 100644 --- a/tdutils/td/utils/port/FileFd.cpp +++ b/tdutils/td/utils/port/FileFd.cpp @@ -8,6 +8,8 @@ #if TD_PORT_WINDOWS #include "td/utils/misc.h" // for narrow_cast + +#include "td/utils/port/Stat.h" #include "td/utils/port/wstring_convert.h" #endif @@ -399,6 +401,11 @@ int64 FileFd::get_size() { return stat().size_; } +static uint64 filetime_to_unix_time_nsec(LONGLONG filetime) { + const auto FILETIME_UNIX_TIME_DIFF = 116444736000000000ll; + return static_cast((filetime - FILETIME_UNIX_TIME_DIFF) * 100); +} + Stat FileFd::stat() { CHECK(!empty()); #if TD_PORT_POSIX @@ -412,8 +419,8 @@ Stat FileFd::stat() { auto error = OS_ERROR("Stat failed"); LOG(FATAL) << error; } - res.atime_nsec_ = basic_info.LastAccessTime.QuadPart * 100; - res.mtime_nsec_ = basic_info.LastWriteTime.QuadPart * 100; + res.atime_nsec_ = filetime_to_unix_time_nsec(basic_info.LastAccessTime.QuadPart); + res.mtime_nsec_ = filetime_to_unix_time_nsec(basic_info.LastWriteTime.QuadPart); res.is_dir_ = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; res.is_reg_ = true;