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

To expand on Blaine’s answer, you can use <zipfileset> child elements to specify permissions:

<zip destfile="build/MyApplication.zip" encoding="UTF-8">

    <zipfileset dir="${content-dir}" encoding="UTF-8"
        includes="**/setup.sh" filemode="755"/>

    <zipfileset dir="${content-dir}" encoding="UTF-8"
        excludes="**/setup.sh"/>

</zip>

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>

I think you can do this with Apache Commons Compress.

First paragraph:

Access to internal and external attributes (which are used to store Unix permission by some zip implementations).

Take a look at the API and look for setUnixMode()


You don't have to switch to tar files. I don't know why people who don't know Ant are offering advice on this topic.

Use zipfileset's filemode parameter. Documented at http://ant.apache.org/manual/Types/zipfileset.html

Tags:

Linux

Java

Zip