From 6d0c86e0826af530b1c1289fe249449abc591694 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 27 Jun 2000 10:42:24 +0000 Subject: [PATCH] Added forceoverwrite attribute to copydir. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267705 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 5 ++++- docs/index.html | 6 ++++++ src/main/org/apache/tools/ant/taskdefs/Copydir.java | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build.xml b/build.xml index e9decf94c..6e4c1edcd 100644 --- a/build.xml +++ b/build.xml @@ -78,7 +78,10 @@ - + diff --git a/docs/index.html b/docs/index.html index b1fec3093..e50252d44 100644 --- a/docs/index.html +++ b/docs/index.html @@ -694,6 +694,12 @@ this attribute has been replaced by the excludes attribute.

the copy No + + forceoverwrite + overwrite existing files even if the destination + files are newer (default is false). + No +

Examples

  <copydir src="${src}/resources"
diff --git a/src/main/org/apache/tools/ant/taskdefs/Copydir.java b/src/main/org/apache/tools/ant/taskdefs/Copydir.java
index aee14ccf5..ea8511754 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Copydir.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Copydir.java
@@ -70,6 +70,7 @@ public class Copydir extends MatchingTask {
     private File srcDir;
     private File destDir;
     private boolean filtering = false;
+    private boolean forceOverwrite = false;
     private Hashtable filecopyList = new Hashtable();
 
     public void setSrc(String src) {
@@ -84,6 +85,10 @@ public class Copydir extends MatchingTask {
         filtering = Project.toBoolean(filter);
     }
 
+    public void setForceoverwrite(String force) {
+        forceOverwrite = Project.toBoolean(force);
+    }
+
     public void execute() throws BuildException {
         if (srcDir == null) {
             throw new BuildException("srcdir attribute must be set!", 
@@ -122,7 +127,8 @@ public class Copydir extends MatchingTask {
             String filename = files[i];
             File srcFile = new File(from, filename);
             File destFile = new File(to, filename);
-            if (srcFile.lastModified() > destFile.lastModified()) {
+            if (forceOverwrite ||
+                (srcFile.lastModified() > destFile.lastModified())) {
                 filecopyList.put(srcFile.getAbsolutePath(),
                     destFile.getAbsolutePath());
             }