Skip to content

Commit

Permalink
Document external_attr better in zip functions.
Browse files Browse the repository at this point in the history
Adds a link to info on external_attr.

Assigns better names to zip variables.
  • Loading branch information
HexDecimal committed May 23, 2023
1 parent 5248eaa commit 3934da5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions delocate/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,16 +827,18 @@ def zip2dir(
"""
# The zipfile module does not preserve permissions correctly
# http://bugs.python.org/issue15795
# external_attr is not well documented but you can learn about it here
# https://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute
with zipfile.ZipFile(zip_fname, "r") as zip:
for name in zip.namelist():
member = zip.getinfo(name)
extracted_path = zip.extract(member, out_dir)
attr = member.external_attr >> 16
unix_attrs = member.external_attr >> 16
if member.is_dir():
os.chmod(extracted_path, 0o755)
elif attr != 0:
mode = attr & 0o777 # Permission bits
os.chmod(extracted_path, mode)
elif unix_attrs != 0:
permissions = unix_attrs & 0o777
os.chmod(extracted_path, permissions)
# Restore timestamp
modified_time = datetime(*member.date_time).timestamp()
os.utime(extracted_path, (modified_time, modified_time))
Expand Down

0 comments on commit 3934da5

Please sign in to comment.