diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 3d7c5649..127c816d 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -369,7 +369,7 @@ static Status check_mtime(std::string &conversion, CSlice original_path) { conversion = parser.read_all().str(); auto r_stat = stat(original_path); uint64 actual_mtime = r_stat.is_ok() ? r_stat.ok().mtime_nsec_ : 0; - if (expected_mtime == actual_mtime) { + if (FileManager::are_modification_times_equal(expected_mtime, actual_mtime)) { LOG(DEBUG) << "File \"" << original_path << "\" modification time " << actual_mtime << " matches"; return Status::OK(); } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index f08a0393..956fee2e 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -782,6 +782,20 @@ string FileManager::get_file_name(FileType file_type, Slice path) { return file_name.str(); } +bool FileManager::are_modification_times_equal(int64 old_mtime, int64 new_mtime) { + if (old_mtime == new_mtime) { + return true; + } + if (old_mtime < new_mtime) { + return false; + } + if (old_mtime - new_mtime == 1000000000 && old_mtime % 1000000000 == 0 && new_mtime % 2000000000 == 0) { + // FAT32 has 2 seconds mtime resolution, but file system sometimes reports odd modification time + return true; + } + return false; +} + Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size) { constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) /* 200 kB */; constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */; @@ -812,8 +826,8 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 if (location.mtime_nsec_ == 0) { LOG(INFO) << "Set file \"" << location.path_ << "\" modification time to " << stat.mtime_nsec_; location.mtime_nsec_ = stat.mtime_nsec_; - } else if (location.mtime_nsec_ != stat.mtime_nsec_) { - LOG(INFO) << "File \"" << location.path_ << "\" was nodified: old mtime = " << location.mtime_nsec_ + } else if (!are_modification_times_equal(location.mtime_nsec_, stat.mtime_nsec_)) { + LOG(INFO) << "File \"" << location.path_ << "\" was modified: old mtime = " << location.mtime_nsec_ << ", new mtime = " << stat.mtime_nsec_; return Status::Error(PSLICE() << "File \"" << location.path_ << "\" was modified"); } diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index b4ad25de..13b82aaa 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -371,6 +371,8 @@ class FileManager : public FileLoadManager::Callback { FileManager &operator=(FileManager &&other) = delete; ~FileManager() override; + static bool are_modification_times_equal(int64 old_mtime, int64 new_mtime); + void init_actor(); FileId dup_file_id(FileId file_id);