From cc432705f28eb85592b6fd077bf95d7c522e3a01 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 4 Jul 2001 14:40:28 +0000 Subject: [PATCH] delete existing target files before copying - this avoids overwriting symlinks and is consistent with Unix's cp(1). PR: 624 Submitted by: ederksen@arrow.lz.att.com (Enno Derksen) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269267 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ src/main/org/apache/tools/ant/Project.java | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index 0213e6a4c..4a2760cee 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -139,6 +139,9 @@ Fixed bugs: * 's uptodate test works even if outputdirectory is not the parent dir of target +* will remove target file (if it exists) before writing to it - + this avoids problems with links on filesystems that support them. + Changes from Ant 1.2 to Ant 1.3 =========================================== diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 5651626f2..d4892b4d3 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -752,8 +752,13 @@ public class Project { boolean overwrite, boolean preserveLastModified) throws IOException { - if (overwrite || + if (overwrite || !destFile.exists() || destFile.lastModified() < sourceFile.lastModified()) { + + if (destFile.exists()) { + destFile.delete(); + } + log("Copy: " + sourceFile.getAbsolutePath() + " -> " + destFile.getAbsolutePath(), MSG_VERBOSE);