Skip to content
Advertisement

Can i store unix permissions in a zip file (built with apache ant)?

I’m building a linux installer for a Java application, and I end up with an install.jar and a setup.sh that I put in a zip file using ant.

The idea is the user unzips the zip file and then runs setup.sh but the trouble is that they always need to chmod setup.sh first to give themselves execute permissions.

I want to remove this step and Im not sure if the problem part is:

  1. That Im building on Windows
  2. That Im building with ant zip task
  3. Or that zips cannot presreve permissions and will always unzip without x permissions.

Advertisement

Answer

You cannot store Linux/Unix file permissions in a ZIP file.

Edit (after comments) by using the “external attributes” field inside the ZIP header these attributes can be store inside a ZIP file. GNU’s unzip is apparently able to read that additional field and restore file permissions. I’m not sure when this was added to the ZIP format as the early versions – coming from a MS-DOS world – did not have support for this.

The TAR format – being a “native” Unix/Linux format – has been designed to include file attributes and Ant can create TAR files that will preserve attributes across all Linux/Unix operating systems.

<tar compression="gzip" destfile="my-archive.tgz">
  <tarfileset mode="544" dir="dir_with_shell_scripts">
     <include name="*.sh"/>
  </tarfileset>
</tar>
Advertisement