Skip to content

Commit 8d7538e

Browse files
committed
PyFilesystem#556 Fallback to alternate mtime depending correctly
This will check the `stat` and `details` namespaces before defaulting to the current time.
1 parent 50b1c99 commit 8d7538e

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

fs/compress.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ def write_zip(
6565
# Python2 expects bytes filenames
6666
zip_name = zip_name.encode(encoding, "replace")
6767

68-
if info.has_namespace("stat"):
69-
# If the file has a stat namespace, get the
70-
# zip time directory from the stat structure
71-
st_mtime = info.get("stat", "st_mtime", None)
72-
_mtime = time.localtime(st_mtime)
73-
zip_time = _mtime[0:6] # type: ZipTime
74-
else:
75-
# Otherwise, use the modified time from details
76-
# namespace.
77-
mt = info.modified or datetime.utcnow()
78-
zip_time = (mt.year, mt.month, mt.day, mt.hour, mt.minute, mt.second)
68+
# If the file has a stat namespace, get the
69+
# zip time directory from the stat structure
70+
st_mtime = info.get("stat", "st_mtime")
71+
# Otherwise, use the modified time from details namespace.
72+
if st_mtime is None:
73+
st_mtime = info.get("details", "modified")
74+
75+
# If st_mtime is still None this will default to current time
76+
zip_time = time.localtime(st_mtime)[:6] # type: ZipTime
7977

8078
# NOTE(@althonos): typeshed's `zipfile.py` on declares
8179
# ZipInfo.__init__ for Python < 3 ?!

0 commit comments

Comments
 (0)