diff --git a/WHATSNEW b/WHATSNEW
index eb8e560e5..1992b61be 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -127,6 +127,10 @@ Other changes:
*
diff --git a/docs/manual/CoreTasks/unzip.html b/docs/manual/CoreTasks/unzip.html index 918acb7a1..dd7415bc1 100644 --- a/docs/manual/CoreTasks/unzip.html +++ b/docs/manual/CoreTasks/unzip.html @@ -30,6 +30,13 @@ carried from zipfile.directory where to store the expanded files. Yes ++ overwrite +Overwrite files, even if they are newer than the + corresponding entries in the archive (true or false, default is + true). +No +Examples
diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java index d66f53ceb..0db5146a7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Expand.java +++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java @@ -66,6 +66,8 @@ import java.util.zip.*; public class Expand extends MatchingTask { private File dest; // req private File source; // req + + private boolean overwrite = true; /** * Do the work. @@ -104,8 +106,6 @@ public class Expand extends MatchingTask { else { expandFile(touch, source, dest); } - - } private void expandFile(Touch touch, File srcF, File dir) { @@ -119,7 +119,15 @@ public class Expand extends MatchingTask { while ((ze = zis.getNextEntry()) != null) { File f = new File(dir, project.translatePath(ze.getName())); try { - log("expand-file " + ze.getName() , Project.MSG_VERBOSE ); + if (!overwrite && f.exists() + && f.lastModified() >= ze.getTime()) { + log("Skipping " + f + " as it is up-to-date", + Project.MSG_DEBUG); + continue; + } + + log("expanding " + ze.getName() + " to "+ f, + Project.MSG_VERBOSE); // create intermediary directories - sometimes zip don't add them File dirF=new File(f.getParent()); dirF.mkdirs(); @@ -179,4 +187,13 @@ public class Expand extends MatchingTask { public void setSrc(File s) { this.source = s; } + + /** + * Should we overwrite files in dest, even if they are newer than + * the corresponding entries in the archive? + */ + public void setOverwrite(boolean b) { + overwrite = b; + } + } diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 59beecad4..980ea9f05 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -69,6 +69,8 @@ public class Untar extends Task { private File dest; // req private File source; // req + private boolean overwrite = true; + /** * Do the work. * @@ -105,8 +107,15 @@ public class Untar extends Task { while ((te = tis.getNextEntry()) != null) { try { File f = new File(dir, project.translatePath(te.getName())); - log("expand-file " + te.getName(), Project.MSG_VERBOSE ); - // create intermediary directories - sometimes tar don't add them + if (!overwrite && f.exists() + && f.lastModified() >= te.getModTime().getTime()) { + log("Skipping " + f + " as it is up-to-date", + Project.MSG_DEBUG); + continue; + } + + log("expanding " + te.getName() + " to "+ f, + Project.MSG_VERBOSE); File dirF=new File(f.getParent()); dirF.mkdirs(); @@ -166,4 +175,13 @@ public class Untar extends Task { public void setSrc(File s) { this.source = s; } + + /** + * Should we overwrite files in dest, even if they are newer than + * the corresponding entries in the archive? + */ + public void setOverwrite(boolean b) { + overwrite = b; + } + }