views:

523

answers:

2

I'm writing an ant build.xml file which does the following:

  • Takes a zipped folder (.zip)
  • Unzips it
  • Adds a number of files
  • Zips up the resulting files

An extract of the code from build.xml:

<!-- Unzip SDK to a temporary directory -->
<unzip src="${zipFile}" dest="tmp"/>

<!-- pull in the files from another directory -->
<copy todir="tmp/someDirectory" >
  <fileset dir="${addedFiles}" />
</copy>

<!-- Zip up modified SDK -->
<zip destfile="${destDir}" basedir="tmp"/>

This all works perfectly, except that the permissions set for the zipped files prior to running the ant build are lost in the zip file created by the ant build. For example, files which were previously executable no longer are.

So my question: is it possible to use ant to add files to a zip archive without destroying the permissions of the already present files?

I'm using Ant 1.7.1

A: 

As far as I know, this feature (preserve0permissions) was introduced with Ant 1.8. Previous versions of Ant did not kept the permissions.

If you're stuck with Ant 1.7.1, you can use Tar that -if I'm not mistaken- stores the permissions.

Vladimir
+1  A: 

Turns out that ant will destroy all information on permissions when unzipping due to a restriction in Java. However, what is possible is to add files to an existing zip file which preserves the permissions of the existing files:

<!-- Add to zip -->
<zip destfile="${existingZipFiledirectory}.zip"
   basedir="${directoryOfFilesToAdd}"
   update="true"
/>

The above script will update the zip file specified with the content in basedir, preserving file permissions in the original zip.

pheelicks