Fix mtime comparison.

GitOrigin-RevId: ba6d77667478bdbb6297b449929b4adcd55c12a1
This commit is contained in:
levlam 2019-03-15 21:52:54 +03:00
parent f20e40990e
commit 6a9a931f29
3 changed files with 19 additions and 3 deletions

View File

@ -369,7 +369,7 @@ static Status check_mtime(std::string &conversion, CSlice original_path) {
conversion = parser.read_all().str(); conversion = parser.read_all().str();
auto r_stat = stat(original_path); auto r_stat = stat(original_path);
uint64 actual_mtime = r_stat.is_ok() ? r_stat.ok().mtime_nsec_ : 0; 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"; LOG(DEBUG) << "File \"" << original_path << "\" modification time " << actual_mtime << " matches";
return Status::OK(); return Status::OK();
} }

View File

@ -782,6 +782,20 @@ string FileManager::get_file_name(FileType file_type, Slice path) {
return file_name.str(); 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) { Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size) {
constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) /* 200 kB */; constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) /* 200 kB */;
constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */; 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) { if (location.mtime_nsec_ == 0) {
LOG(INFO) << "Set file \"" << location.path_ << "\" modification time to " << stat.mtime_nsec_; LOG(INFO) << "Set file \"" << location.path_ << "\" modification time to " << stat.mtime_nsec_;
location.mtime_nsec_ = stat.mtime_nsec_; location.mtime_nsec_ = stat.mtime_nsec_;
} else if (location.mtime_nsec_ != stat.mtime_nsec_) { } else if (!are_modification_times_equal(location.mtime_nsec_, stat.mtime_nsec_)) {
LOG(INFO) << "File \"" << location.path_ << "\" was nodified: old mtime = " << location.mtime_nsec_ LOG(INFO) << "File \"" << location.path_ << "\" was modified: old mtime = " << location.mtime_nsec_
<< ", new mtime = " << stat.mtime_nsec_; << ", new mtime = " << stat.mtime_nsec_;
return Status::Error(PSLICE() << "File \"" << location.path_ << "\" was modified"); return Status::Error(PSLICE() << "File \"" << location.path_ << "\" was modified");
} }

View File

@ -371,6 +371,8 @@ class FileManager : public FileLoadManager::Callback {
FileManager &operator=(FileManager &&other) = delete; FileManager &operator=(FileManager &&other) = delete;
~FileManager() override; ~FileManager() override;
static bool are_modification_times_equal(int64 old_mtime, int64 new_mtime);
void init_actor(); void init_actor();
FileId dup_file_id(FileId file_id); FileId dup_file_id(FileId file_id);