From 38bb66a776ef18070e7d46f4daeee35acb8c3e36 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 13 May 2021 19:40:10 +0200 Subject: [PATCH] Update file metadata in more cases PFERD now not only updates file metadata when a file is successfully added or changed, but also when a file is downloaded and then detected to be unchanged. This could occur for example if a remote file's modification time was bumped, possibly because somebody touched the file without changing it. --- PFERD/output_dir.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/PFERD/output_dir.py b/PFERD/output_dir.py index 635ee43..571d73d 100644 --- a/PFERD/output_dir.py +++ b/PFERD/output_dir.py @@ -303,6 +303,11 @@ class OutputDirectory: return None + def _update_metadata(self, info: DownloadInfo) -> None: + if mtime := info.heuristics.mtime: + mtimestamp = mtime.timestamp() + os.utime(info.local_path, times=(mtimestamp, mtimestamp)) + async def _after_download(self, info: DownloadInfo) -> None: changed = False @@ -314,6 +319,7 @@ class OutputDirectory: if info.local_path.exists(): changed = True if filecmp.cmp(info.local_path, info.tmp_path): + self._update_metadata(info) info.tmp_path.unlink() return @@ -321,15 +327,8 @@ class OutputDirectory: info.tmp_path.unlink() return - # Modify metadata if necessary - if mtime := info.heuristics.mtime: - # TODO Pick an implementation - # Rounding up to avoid inaccuracies in how the OS stores timestamps - # mtimestamp = math.ceil(mtime.timestamp()) - mtimestamp = mtime.timestamp() - os.utime(info.tmp_path, times=(mtimestamp, mtimestamp)) - info.tmp_path.replace(info.local_path) + self._update_metadata(info) if changed: self._conductor.print(