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

Fix extracted files permissions #609

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/wheel/cli/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ def unpack(path: str, dest: str = ".") -> None:
namever = wf.parsed_filename.group("namever")
destination = Path(dest) / namever
print(f"Unpacking to: {destination}...", end="", flush=True)
for zinfo in wf.filelist:
wf.extract(zinfo, destination)

# Set permissions to the same values as they were set in the archive
# We have to do this manually due to
# https://github.com/python/cpython/issues/59999
permissions = zinfo.external_attr >> 16 & 0o777
destination.joinpath(zinfo.filename).chmod(permissions)
wf.extractall(destination)

print("OK")
13 changes: 13 additions & 0 deletions src/wheel/wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import stat
import time
from io import StringIO, TextIOWrapper
from pathlib import Path
from typing import IO, TYPE_CHECKING, Literal
from zipfile import ZIP_DEFLATED, ZipFile, ZipInfo

Expand Down Expand Up @@ -225,3 +226,15 @@ def close(self):
self.writestr(self.record_path, data.getvalue())

ZipFile.close(self)

def _extract_member(self, member, targetpath, pwd):
targetpath = super()._extract_member(member, targetpath, pwd)
if not isinstance(member, ZipInfo):
member = self.getinfo(member)

# Set permissions to the same values as they were set in the archive
# We have to do this manually due to
# https://github.com/python/cpython/issues/59999
permissions = member.external_attr >> 16 & 0o777
Path(targetpath).chmod(permissions)
return targetpath