Skip to content

Commit

Permalink
fix: regular file flag was not set
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Apr 20, 2023
1 parent 0c6608f commit 9fc3ba0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flit_core/flit_core/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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('=')
Expand Down
5 changes: 5 additions & 0 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import configparser
import os
import stat
from pathlib import Path
import tempfile
from unittest import skipIf
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9fc3ba0

Please sign in to comment.