diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 6bca6b754..cfebd0fc2 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -26,16 +26,6 @@ namespace td { int VERBOSITY_NAME(file_gc) = VERBOSITY_NAME(INFO); -void FileGcWorker::do_remove_file(const FullFileInfo &info) { - // LOG(WARNING) << "Gc remove file: " << tag("path", file) << tag("mtime", stat.mtime_nsec_ / 1000000000) - // << tag("atime", stat.atime_nsec_ / 1000000000); - // TODO: remove file from database too - auto status = unlink(info.path); - LOG_IF(WARNING, status.is_error()) << "Failed to unlink file during files gc: " << status; - send_closure(G()->file_manager(), &FileManager::on_file_unlink, - FullLocalFileLocation(info.file_type, info.path, info.mtime_nsec)); -} - void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector files, Promise promise) { auto begin_time = Time::now(); @@ -92,8 +82,17 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector now - max_time_from_last_access + auto do_remove_file = [](const FullFileInfo &info) { + auto status = unlink(info.path); + LOG_IF(WARNING, status.is_error()) << "Failed to unlink file \"" << info.path << "\" during files gc: " << status; + send_closure(G()->file_manager(), &FileManager::on_file_unlink, + FullLocalFileLocation(info.file_type, info.path, info.mtime_nsec)); + }; + double now = Clocks::system(); + + // Keep all immune files + // Remove all files with (atime > now - max_time_from_last_access) td::remove_if(files, [&](const FullFileInfo &info) { if (token_) { return false; @@ -113,14 +112,14 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector(info.mtime_nsec / 1000000000) > now - parameters.immunity_delay) { + if (info.mtime_nsec * 1e-9 > now - parameters.immunity_delay) { // new files are immune to gc time_immunity_ignored_cnt++; new_stats.add(FullFileInfo(info)); return true; } - if (static_cast(info.atime_nsec / 1000000000) < now - parameters.max_time_from_last_access) { + if (info.atime_nsec * 1e-9 < now - parameters.max_time_from_last_access) { do_remove_file(info); total_removed_size += info.size; remove_by_atime_cnt++; diff --git a/td/telegram/files/FileGcWorker.h b/td/telegram/files/FileGcWorker.h index d5dbb1d00..428beb0fa 100644 --- a/td/telegram/files/FileGcWorker.h +++ b/td/telegram/files/FileGcWorker.h @@ -28,7 +28,6 @@ class FileGcWorker : public Actor { private: ActorShared<> parent_; CancellationToken token_; - void do_remove_file(const FullFileInfo &info); }; } // namespace td diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 273008484..7364a3c52 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1020,6 +1020,7 @@ FileId FileManager::register_empty(FileType type) { } void FileManager::on_file_unlink(const FullLocalFileLocation &location) { + // TODO: remove file from the database too auto it = local_location_to_file_id_.find(location); if (it == local_location_to_file_id_.end()) { return;