Commit 1989f919 authored by Christian Schudt's avatar Christian Schudt

Fix error, which was introduced with e0bc007f.

parent 5e2f097a
...@@ -742,24 +742,40 @@ public class XMLProperties { ...@@ -742,24 +742,40 @@ public class XMLProperties {
Log.error("Unable to save XML properties; no file specified"); Log.error("Unable to save XML properties; no file specified");
return; return;
} }
boolean error = false;
// Write data out to a temporary file first. // Write data out to a temporary file first.
File tempFile = new File(file.getParentFile(), file.getName() + ".tmp"); File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");;
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"))) { try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"))) {
OutputFormat prettyPrinter = OutputFormat.createPrettyPrint(); OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter); XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
xmlWriter.write(document); xmlWriter.write(document);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
// There were errors so abort replacing the old property file.
error = true;
}
// No errors occurred, so delete the main file.
if (!error) {
// Delete the old file so we can replace it. // Delete the old file so we can replace it.
if (!file.delete()) { if (!file.delete()) {
Log.error("Error deleting property file: " + file.getAbsolutePath()); Log.error("Error deleting property file: " + file.getAbsolutePath());
return; return;
} }
// Copy new contents to the file. // Copy new contents to the file.
copy(tempFile, file); try {
copy(tempFile, file);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
// There were errors so abort replacing the old property file.
error = true;
}
// If no errors, delete the temp file. // If no errors, delete the temp file.
tempFile.delete(); if (!error) {
} catch (Exception e) { tempFile.delete();
Log.error(e.getMessage(), e); }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment