diff --git a/my/core/kompress.py b/my/core/kompress.py index 8725bcf..93a19a0 100644 --- a/my/core/kompress.py +++ b/my/core/kompress.py @@ -3,6 +3,7 @@ Various helpers for compression """ from __future__ import annotations +from datetime import datetime import pathlib from pathlib import Path import sys @@ -198,3 +199,22 @@ class ZipPath(ZipPathBase): def __hash__(self) -> int: return hash((self.filepath, self.subpath)) + + def stat(self) -> os.stat_result: + # NOTE: zip datetimes have no notion of time zone, usually they just keep local time? + # see https://en.wikipedia.org/wiki/ZIP_(file_format)#Structure + dt = datetime(*self.root.getinfo(str(self.subpath)).date_time) + ts = int(dt.timestamp()) + params = dict( + st_mode=0, + st_ino=0, + st_dev=0, + st_nlink=1, + st_uid=1000, + st_gid=1000, + st_size=0, # todo compute it properly? + st_atime=ts, + st_mtime=ts, + st_ctime=ts, + ) + return os.stat_result(tuple(params.values())) diff --git a/tests/core/test_kompress.py b/tests/core/test_kompress.py index 949a7f1..481a025 100644 --- a/tests/core/test_kompress.py +++ b/tests/core/test_kompress.py @@ -1,3 +1,4 @@ +from datetime import datetime import lzma from pathlib import Path import sys @@ -115,3 +116,10 @@ def test_zippath() -> None: iterdir_res = list((zp / 'gdpr_export').iterdir()) assert len(iterdir_res) == 3 assert all(isinstance(p, Path) for p in iterdir_res) + + # date recorded in the zip archive + assert (zp / 'gdpr_export/comments/comments.json').stat().st_mtime > 1625000000 + # TODO ugh. + # unzip -l shows the date as 2021-07-01 09:43 + # however, python reads it as 2021-07-01 01:43 ?? + # don't really feel like dealing with this for now, it's not tz aware anyway