0

I have created a zip archive in Python with shutil.make_archive, but when I extract it with both shutil.unpack_archive and zipfile.ZipFile(file).extractall() the file modes are changed as:

old mode 100755
new mode 100644

Currently I have to make a subprocess call to run('unzip ...') for it to work? Is there a Python builtin that I can use to preserve the file modes?

Patrick Kwok
  • 42
  • 10

1 Answers1

0

As far as I know there is no inbuild way to preserve the permission. I think the argument is, that it is not part of the zip-standard and a unix-extension.

There are two workaround I know:

  • inspect the attributes stored in the zip file in ZipInfo.external_attr and setting it yourself with os.chmod, described here
  • calling the unix tool unzip from within python that does the right thing, described here

One thing I don't know is if shutil.make_archive stores these extended permissions. If not one would use the same stragies above for zipping...

Chris
  • 2,461
  • 1
  • 23
  • 29