Skip to content

Commit a67aa87

Browse files
authored
fix: clip zip timestamp to 1980-01-01 (#568)
zip timestamps do not use POSIX timestamp, they use DOS timestamps that starts on 1980-01-01.
1 parent 8964d1e commit a67aa87

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/auditwheel/tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ def dir2zip(
142142
st = in_dir.stat()
143143
date_time = datetime.fromtimestamp(st.st_mtime, tz=timezone.utc)
144144
date_time_args = date_time.timetuple()[:6]
145+
if date_time_args < (1980, 1, 1, 0, 0, 0):
146+
logger.warning("dir2zip, clipping timestamp to 1980-01-01")
147+
date_time_args = (1980, 1, 1, 0, 0, 0)
145148
compression = zipfile.ZIP_DEFLATED
146149
with zipfile.ZipFile(zip_fname, "w", compression=compression) as z:
147150
for dname, _, files in walk(in_dir):

tests/integration/test_bundled_wheels.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import importlib
44
import os
55
import platform
6-
import subprocess
76
import sys
87
import zipfile
98
from argparse import Namespace
@@ -138,29 +137,25 @@ def test_analyze_wheel_abi_static_exe(caplog):
138137
assert result.overall_policy.name == "manylinux_2_5_x86_64"
139138

140139

141-
@pytest.mark.skipif(platform.machine() != "x86_64", reason="only checked on x86_64")
142-
def test_wheel_source_date_epoch(tmp_path, monkeypatch):
143-
wheel_build_path = tmp_path / "wheel"
144-
subprocess.run(
145-
[
146-
sys.executable,
147-
"-m",
148-
"pip",
149-
"wheel",
150-
"--no-deps",
151-
"-w",
152-
wheel_build_path,
153-
HERE / "sample_extension",
154-
],
155-
check=True,
140+
@pytest.mark.parametrize(
141+
"timestamp",
142+
[
143+
(0, 315532800), # zip timestamp starts 1980-01-01, not 1970-01-01
144+
(315532799, 315532800), # zip timestamp starts 1980-01-01, not 1970-01-01
145+
(315532801, 315532800), # zip timestamp round odd seconds down to even seconds
146+
(315532802, 315532802),
147+
(650203201, 650203200), # zip timestamp round odd seconds down to even seconds
148+
],
149+
)
150+
def test_wheel_source_date_epoch(timestamp, tmp_path, monkeypatch):
151+
wheel_path = (
152+
HERE / "arch-wheels/musllinux_1_2/testsimple-0.0.1-cp312-cp312-linux_x86_64.whl"
156153
)
157-
158-
wheel_path, *_ = list(wheel_build_path.glob("*.whl"))
159154
wheel_output_path = tmp_path / "out"
160155
args = Namespace(
161156
LIB_SDIR=".libs",
162157
ONLY_PLAT=False,
163-
PLAT="manylinux_2_5_x86_64",
158+
PLAT="auto",
164159
STRIP=False,
165160
UPDATE_TAGS=True,
166161
WHEEL_DIR=wheel_output_path,
@@ -173,7 +168,8 @@ def test_wheel_source_date_epoch(tmp_path, monkeypatch):
173168
prog="auditwheel",
174169
verbose=1,
175170
)
176-
monkeypatch.setenv("SOURCE_DATE_EPOCH", "650203200")
171+
172+
monkeypatch.setenv("SOURCE_DATE_EPOCH", str(timestamp[0]))
177173
# patchelf might not be available as we aren't running in a manylinux container
178174
# here. We don't need need it in this test, so just patch it.
179175
with mock.patch("auditwheel.patcher._verify_patchelf"):
@@ -182,6 +178,5 @@ def test_wheel_source_date_epoch(tmp_path, monkeypatch):
182178
output_wheel, *_ = list(wheel_output_path.glob("*.whl"))
183179
with zipfile.ZipFile(output_wheel) as wheel_file:
184180
for file in wheel_file.infolist():
185-
assert (
186-
datetime(*file.date_time, tzinfo=timezone.utc).timestamp() == 650203200
187-
)
181+
file_date_time = datetime(*file.date_time, tzinfo=timezone.utc)
182+
assert file_date_time.timestamp() == timestamp[1]

0 commit comments

Comments
 (0)