When dealing with duplicated zipentries, Zip checks modification times before overwriting the zipentry. If you specify duplicate="add", zipentries will be overwriten only if the present zipentry is older than the one you're trying to add. In some situations it would be nice to override this behaviour and force zip to overwrite zipentries even if the file you're adding is older than the zipentry in the zip file. The following patch should do the trick (please shout if there is a better way of submitting patch suggestions): Index: src/main/org/apache/tools/ant/taskdefs/Zip.java =================================================================== --- src/main/org/apache/tools/ant/taskdefs/Zip.java (revision 384498) +++ src/main/org/apache/tools/ant/taskdefs/Zip.java (working copy) @@ -1130,11 +1130,15 @@ resources = selectFileResources(resources); } - newerResources[i] = - ResourceUtils.selectOutOfDateSources(this, + if(duplicate.equals("overwrite")){ + newerResources[i] = resources; + } else { + newerResources[i] = + ResourceUtils.selectOutOfDateSources(this, resources, myMapper, getZipScanner()); + } needsUpdate = needsUpdate || (newerResources[i].length > 0); if (needsUpdate && !doUpdate) { @@ -1647,7 +1651,7 @@ * @see EnumeratedAttribute#getValues() */ public String[] getValues() { - return new String[] {"add", "preserve", "fail"}; + return new String[] {"add", "preserve", "fail", "overwrite"}; } }
Created attachment 17862 [details] ZIp.java patch doh! didn't see the "add attachment" before...
Just to clarify, the proposed patch would add a 'duplicate' value. Currently the duplicate attribute in <zip> supports "add", "preserve" and "fail". After the patch, the attribute would support "add", "preserve", "fail" and "overwrite".
This patch really isn't making sense with me... maybe if you attached a testcase I would understand what it's supposed to accomplish. Also, OSS projects get happy when patches are accompanied by tests... :)
*** Bug 22930 has been marked as a duplicate of this bug. ***
the use-case is "always replace existing archive entries with the local files even if the archive entries seem to be newer, leave all other archive entries alone"