Bug 38918 - Add 'real' overwrite support to Zip-based tasks
Summary: Add 'real' overwrite support to Zip-based tasks
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.5
Hardware: All All
: P3 enhancement with 4 votes (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Keywords: PatchAvailable
: 22930 (view as bug list)
Depends on:
Reported: 2006-03-10 10:47 UTC by Horaci Macias
Modified: 2009-07-31 06:28 UTC (History)
1 user (show)

ZIp.java patch (1.27 KB, patch)
2006-03-10 10:48 UTC, Horaci Macias
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Horaci Macias 2006-03-10 10:47:11 UTC
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,
+            }
             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"};
Comment 1 Horaci Macias 2006-03-10 10:48:08 UTC
Created attachment 17862 [details]
ZIp.java patch

doh! didn't see the "add attachment" before...
Comment 2 Horaci Macias 2006-03-10 10:50:40 UTC
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
Comment 3 Matt Benson 2006-04-11 21:47:13 UTC
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... :)
Comment 4 Stefan Bodewig 2009-07-31 06:26:30 UTC
*** Bug 22930 has been marked as a duplicate of this bug. ***
Comment 5 Stefan Bodewig 2009-07-31 06:28:20 UTC
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"