ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r883514 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
Date Mon, 23 Nov 2009 21:57:20 GMT
Author: jglick
Date: Mon Nov 23 21:57:19 2009
New Revision: 883514

URL: http://svn.apache.org/viewvc?rev=883514&view=rev
Log:
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.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java?rev=883514&r1=883513&r2=883514&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java Mon Nov
23 21:57:19 2009
@@ -40,6 +40,7 @@
 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 @@
         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());
         }
     }



Mime
View raw message