Browse Source

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
master
Jesse N. Glick 15 years ago
parent
commit
42b64be716
1 changed files with 10 additions and 7 deletions
  1. +10
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

+ 10
- 7
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -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());
}
}


Loading…
Cancel
Save