Pull requests

#14 Merged

Set permissions when extracting from zipfile.

  1. Jonathan Lange

unpack_tarfile preserves the permissions that are in the tarfile but unpack_zipfile discards the permissions that are in the zipfile. This inconsistency makes the system harder to understand, and also makes it rather tricky to include non-Python executables in a Python distribution, which one must do from time to time.

The patch simply looks in top couple of bytes of the ZipInfo.external_attr variable for each of the extracted files and chmods them after extraction.

I couldn't see any existing tests for archive_util, so I didn't add any in this patch.

Thanks, jml

  • Learn about pull requests

Comments (3)

  1. Jason R. Coombs

    This looks reasonable. What happens if info.external_attr was not defined on the ZipInfo object (or is that not possible)? What if higher bits were set? What if the zip file was created by another Zip engine (such as on Windows)?

    As long as we have confidence we won't create a regression by including this step, I'll pull it in.

    1. Jonathan Lange author

      Thanks for replying so promptly! I'm shamed that I'm only following up now.

      Good questions all. Here are my answers:

      • `external_attr` is always defined on `ZipInfo`. I verified this by looking at the definition of `ZipInfo` in zipfile.py in the Pythons installed on my system: 2.5, 2.6, 2.7 and 3.2. By default, it is set to 0.
      • For zip files created on Windows, `external_attr` is set to 0. I can't figure out what `os.chmod(path, 0)` does on Windows, so I've uploaded a change that guards the chmod, first checking that it's not 0.

      Sorry for the delay in response. Please let me know if you've got other questions, and I'm sure I'll answer more swiftly this time.

      Thanks, jml