From 9fc3ba061638ec5d10bf6085378a8774c4cd2f61 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 13 Mar 2023 12:02:15 -0400 Subject: [PATCH] fix: regular file flag was not set Signed-off-by: Henry Schreiner --- flit_core/flit_core/wheel.py | 5 +++-- tests/test_wheel.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/flit_core/flit_core/wheel.py b/flit_core/flit_core/wheel.py index 08cb70ae..b4a44b0d 100644 --- a/flit_core/flit_core/wheel.py +++ b/flit_core/flit_core/wheel.py @@ -33,7 +33,7 @@ def _write_wheel_file(f, supports_py2=False): def _set_zinfo_mode(zinfo, mode): - # Set the bits for the mode and bit 0xFFFF for “regular file” + # Set the bits for the mode zinfo.external_attr = mode << 16 @@ -147,7 +147,8 @@ def _write_to_zip(self, rel_path, mode=0o644): # give you the exact same result. date_time = self.source_time_stamp or (2016, 1, 1, 0, 0, 0) zi = zipfile.ZipInfo(rel_path, date_time) - _set_zinfo_mode(zi, mode) + # Also sets bit 0x8000 for "regular file" (S_IFREG) + _set_zinfo_mode(zi, mode | stat.S_IFREG) b = sio.getvalue().encode('utf-8') hashsum = hashlib.sha256(b) hash_digest = urlsafe_b64encode(hashsum.digest()).decode('ascii').rstrip('=') diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 3b883913..e39a2b0e 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -1,5 +1,6 @@ import configparser import os +import stat from pathlib import Path import tempfile from unittest import skipIf @@ -199,6 +200,10 @@ def test_permissions_normed(copy_sample): perms = (info.external_attr >> 16) & 0o777 assert perms == 0o644, oct(perms) + info = zf.getinfo('module1-0.1.dist-info/RECORD') + perms = (info.external_attr >> 16) & stat.S_IFREG + assert perms + def test_compression(tmp_path): info = make_wheel_in(samples_dir / 'module1_toml' / 'pyproject.toml', tmp_path) assert_isfile(info.file)