kompress.ZipPath: support stat().st_mtime
This commit is contained in:
parent
f9f73dda24
commit
915cfe69b3
2 changed files with 28 additions and 0 deletions
|
@ -3,6 +3,7 @@ Various helpers for compression
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import pathlib
|
import pathlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
@ -198,3 +199,22 @@ class ZipPath(ZipPathBase):
|
||||||
|
|
||||||
def __hash__(self) -> int:
|
def __hash__(self) -> int:
|
||||||
return hash((self.filepath, self.subpath))
|
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()))
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from datetime import datetime
|
||||||
import lzma
|
import lzma
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
@ -115,3 +116,10 @@ def test_zippath() -> None:
|
||||||
iterdir_res = list((zp / 'gdpr_export').iterdir())
|
iterdir_res = list((zp / 'gdpr_export').iterdir())
|
||||||
assert len(iterdir_res) == 3
|
assert len(iterdir_res) == 3
|
||||||
assert all(isinstance(p, Path) for p in iterdir_res)
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue