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

Ensure that the timezone doesn't leak into zips. #8

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog — repro-zipfile

## v0.3.1 (2024-02-02)

- Fixed bug that caused timestamps set by `SOURCE_DATE_EPOCH` to be affected by the local system timezone. It now always uses UTC. ([PR #8](https://github.com/drivendataorg/repro-zipfile/pull/8) from [@thatch](https://github.com/thatch))

## v0.3.0 (2024-01-27)

- Added a `cli` installation extra for installing the rpzip package, which includes a command-line program
Expand Down
4 changes: 2 additions & 2 deletions repro_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
_MASK_COMPRESS_OPTION_1 = 0x02

__version__ = "0.3.0"
__version__ = "0.3.1"


def date_time() -> Union[time.struct_time, Tuple[int, int, int, int, int, int]]:
Expand All @@ -21,7 +21,7 @@ def date_time() -> Union[time.struct_time, Tuple[int, int, int, int, int, int]]:
"""
source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH", None)
if source_date_epoch is not None:
return time.localtime(int(source_date_epoch))
return time.gmtime(int(source_date_epoch))
return (1980, 1, 1, 0, 0, 0)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from time import sleep
from zipfile import ZipFile, ZipInfo

try:
from time import tzset
except ImportError:
tzset = None

from repro_zipfile import ReproducibleZipFile
from tests.utils import (
assert_archive_contents_equals,
Expand Down Expand Up @@ -195,6 +200,9 @@ def test_write_single_file_source_date_epoch(base_path, monkeypatch):
zp.write(data_file)

monkeypatch.setenv("SOURCE_DATE_EPOCH", "1691732367")
if tzset:
monkeypatch.setenv("TZ", "America/Chicago")
tzset()

# With SOURCE_DATE_EPOCH set
arc_sde1 = base_path / "with_sde1.zip"
Expand All @@ -203,6 +211,10 @@ def test_write_single_file_source_date_epoch(base_path, monkeypatch):

sleep(2)
data_file.touch()
if tzset:
# Set a different timezone to make sure it doesn't affect the set time
monkeypatch.setenv("TZ", "America/Los_Angeles")
tzset()

arc_sde2 = base_path / "with_sde2.zip"
with ReproducibleZipFile(arc_sde2, "w") as zp:
Expand Down
Loading