diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java index 40cf03c8a8..deddaa9500 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java @@ -317,48 +317,47 @@ public class JAXBConfigurationEntryStore implements ConfigurationEntryStore { + try (IndentXMLStreamWriter writer = XmlStreams.createWriter(temp)) { + writer.writeStartDocument(); - // configuration start - writer.writeStartElement(TAG_CONFIGURATION); + // configuration start + writer.writeStartElement(TAG_CONFIGURATION); - Marshaller m = context.createMarshaller(); + Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); + m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - for (Entry e : entries.entrySet()) - { + for (Entry e : entries.entrySet()) { - // entry start - writer.writeStartElement(TAG_ENTRY); + // entry start + writer.writeStartElement(TAG_ENTRY); - // key start - writer.writeStartElement(TAG_KEY); - writer.writeCharacters(e.getKey()); + // key start + writer.writeStartElement(TAG_KEY); + writer.writeCharacters(e.getKey()); - // key end - writer.writeEndElement(); + // key end + writer.writeEndElement(); - // value - JAXBElement je = new JAXBElement(QName.valueOf(TAG_VALUE), type, - e.getValue()); + // value + JAXBElement je = new JAXBElement<>(QName.valueOf(TAG_VALUE), type, + e.getValue()); - m.marshal(je, writer); + m.marshal(je, writer); - // entry end - writer.writeEndElement(); - } + // entry end + writer.writeEndElement(); + } - // configuration end - writer.writeEndElement(); - writer.writeEndDocument(); - } - catch (Exception ex) - { - throw new StoreException("could not store configuration", ex); - } + // configuration end + writer.writeEndElement(); + writer.writeEndDocument(); + } + }, + file.toPath() + ); } //~--- fields --------------------------------------------------------------- diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationStore.java index ac1477d7ea..92bd0fbcc4 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationStore.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationStore.java @@ -113,7 +113,10 @@ public class JAXBConfigurationStore extends AbstractStore { Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(object, configFile); + CopyOnWrite.withTemporaryFile( + temp -> marshaller.marshal(object, temp.toFile()), + configFile.toPath() + ); } catch (JAXBException ex) { throw new StoreException("failed to marshall object", ex);