From 42b64be7164de91699c8327cd25e1c118d20068b Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Mon, 23 Nov 2009 21:57:19 +0000 Subject: [PATCH] Trying to improve on r881624 robustness fix: 1. Use FileUtils.tryHardToDelete to delete possibly corrupt properties file. 2. Do not try to delete until after closing output stream. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@883514 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/PropertyFile.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java index 47984e36f..2483cf6e2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java @@ -40,6 +40,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.apache.tools.ant.util.LayoutPreservingProperties; import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.tools.ant.util.FileUtils; /** *Modifies settings in a property file. @@ -243,14 +244,16 @@ public class PropertyFile extends Task { try { OutputStream os = new FileOutputStream(propertyfile); try { - os.write(baos.toByteArray()); - } catch (IOException x) { - propertyfile.delete(); // possibly corrupt - throw new BuildException(x, getLocation()); - } finally { - os.close(); + try { + os.write(baos.toByteArray()); + } finally { + os.close(); + } + } catch (IOException x) { // possibly corrupt + FileUtils.getFileUtils().tryHardToDelete(propertyfile); + throw x; } - } catch (IOException x) { + } catch (IOException x) { // opening, writing, or closing throw new BuildException(x, getLocation()); } }