Skip to content

Commit

Permalink
Fix ZipFile mode not set
Browse files Browse the repository at this point in the history
  • Loading branch information
delijati authored and mergify-bot committed Mar 14, 2022
1 parent 98728b1 commit 3c6c335
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion setuptools/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
"__import__('pkg_resources').declare_namespace(__name__)\n"


class ZipFilePreserveMode(zipfile.ZipFile):
""" Extended ZipFile class to preserve file mode """
def _extract_member(self, member, targetpath, pwd):
if not isinstance(member, zipfile.ZipInfo):
member = self.getinfo(member)

targetpath = super()._extract_member(member, targetpath, pwd)

attr = member.external_attr >> 16
if attr != 0:
os.chmod(targetpath, attr)
return targetpath


def unpack(src_dir, dst_dir):
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
for dirpath, dirnames, filenames in os.walk(src_dir):
Expand Down Expand Up @@ -91,7 +105,7 @@ def get_dist_info(self, zf):

def install_as_egg(self, destination_eggdir):
'''Install wheel as an egg directory.'''
with zipfile.ZipFile(self.filename) as zf:
with ZipFilePreserveMode(self.filename) as zf:
self._install_as_egg(destination_eggdir, zf)

def _install_as_egg(self, destination_eggdir, zf):
Expand Down

0 comments on commit 3c6c335

Please sign in to comment.