mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
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.
This commit is contained in:
parent
68781a88ab
commit
38bb66a776
@ -303,6 +303,11 @@ class OutputDirectory:
|
|||||||
|
|
||||||
return None
|
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:
|
async def _after_download(self, info: DownloadInfo) -> None:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
@ -314,6 +319,7 @@ class OutputDirectory:
|
|||||||
if info.local_path.exists():
|
if info.local_path.exists():
|
||||||
changed = True
|
changed = True
|
||||||
if filecmp.cmp(info.local_path, info.tmp_path):
|
if filecmp.cmp(info.local_path, info.tmp_path):
|
||||||
|
self._update_metadata(info)
|
||||||
info.tmp_path.unlink()
|
info.tmp_path.unlink()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -321,15 +327,8 @@ class OutputDirectory:
|
|||||||
info.tmp_path.unlink()
|
info.tmp_path.unlink()
|
||||||
return
|
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)
|
info.tmp_path.replace(info.local_path)
|
||||||
|
self._update_metadata(info)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
self._conductor.print(
|
self._conductor.print(
|
||||||
|
Loading…
Reference in New Issue
Block a user