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

前端 未结 7 1637
抹茶落季
抹茶落季 2021-01-02 02:03

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 unzi

相关标签:
7条回答
  • 2021-01-02 02:29

    If you use a tar file instead of a zip file, it should preserve the permissions for you. The files' owners and groups might not match up, but the permission bits will.

    0 讨论(0)
  • 2021-01-02 02:32

    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()

    0 讨论(0)
  • 2021-01-02 02:37
    <shellscript shell="sh" dir="abc" failonerror="true">
                zip -ry abc.zip *
    </shellscript>
    

    The ant script above invokes a shell script to create the zip archive in which the permissions are very well preserved. It works with Ant 1.7 and above. However I have not tried verified running this ant script on windows. This works very well on mac.

    0 讨论(0)
  • 2021-01-02 02:40

    zip/unzip in modern linux distros will preserve file permissions. But you need to make sure that the zip in windows honours this.

    0 讨论(0)
  • 2021-01-02 02:40

    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>
    
    0 讨论(0)
  • 2021-01-02 02:41

    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>
    
    0 讨论(0)
提交回复
热议问题