Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#556 Fallback to alternate mtime correctly #557

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Fix an issue with `fs.compress.write_zip` that would cause an error
interacting with `S3FS` directory entries.
([#557](https://github.com/PyFilesystem/pyfilesystem2/pull/557))
Closes [#556](https://github.com/PyFilesystem/pyfilesystem2/issues/556).


### Added

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Many thanks to the following developers for contributing to this project:
- [George Macon](https://github.com/gmacon)
- [Giampaolo Cimino](https://github.com/gpcimino)
- [@Hoboneer](https://github.com/Hoboneer)
- [James Emerton](https://github.com/james-emerton)
- [Jen Hagg](https://github.com/jenhagg)
- [Jon Hagg](https://github.com/jon-hagg)
- [Joseph Atkins-Turkish](https://github.com/Spacerat)
- [Joshua Tauberer](https://github.com/JoshData)
- [Justin Charlong](https://github.com/jcharlong)
Expand Down
20 changes: 9 additions & 11 deletions fs/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ def write_zip(
# Python2 expects bytes filenames
zip_name = zip_name.encode(encoding, "replace")

if info.has_namespace("stat"):
# If the file has a stat namespace, get the
# zip time directory from the stat structure
st_mtime = info.get("stat", "st_mtime", None)
_mtime = time.localtime(st_mtime)
zip_time = _mtime[0:6] # type: ZipTime
else:
# Otherwise, use the modified time from details
# namespace.
mt = info.modified or datetime.utcnow()
zip_time = (mt.year, mt.month, mt.day, mt.hour, mt.minute, mt.second)
# If the file has a stat namespace, get the
# zip time directory from the stat structure
st_mtime = info.get("stat", "st_mtime")
# Otherwise, use the modified time from details namespace.
if st_mtime is None:
st_mtime = info.get("details", "modified")

# If st_mtime is still None this will default to current time
zip_time = time.localtime(st_mtime)[:6] # type: ZipTime

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