marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject git commit: fix MARMOTTA-257 (save configuration first to temp file and then move to original destination)
Date Tue, 07 Jan 2014 16:50:39 GMT
Updated Branches:
  refs/heads/develop 030a0a1df -> 86d1a4004


fix MARMOTTA-257 (save configuration first to temp file and then move to original destination)


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/86d1a400
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/86d1a400
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/86d1a400

Branch: refs/heads/develop
Commit: 86d1a4004e5f0c03c18ad1a8ad010a740181575f
Parents: 030a0a1
Author: Sebastian Schaffert <sschaffert@apache.org>
Authored: Tue Jan 7 17:50:35 2014 +0100
Committer: Sebastian Schaffert <sschaffert@apache.org>
Committed: Tue Jan 7 17:50:35 2014 +0100

----------------------------------------------------------------------
 .../config/ConfigurationServiceImpl.java        | 21 ++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/86d1a400/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
index df13c5e..50a52af 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
@@ -44,6 +44,10 @@ import java.io.IOException;
 import java.lang.reflect.Array;
 import java.net.URL;
 import java.net.UnknownHostException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 import java.util.*;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -1133,16 +1137,25 @@ public class ConfigurationServiceImpl implements ConfigurationService
{
     protected void save() {
         if(saveConfiguration instanceof PropertiesConfiguration) {
             try {
-                ((PropertiesConfiguration)saveConfiguration).save();
-            } catch (ConfigurationException e) {
+                Path tmpFile = Files.createTempFile(FileSystems.getDefault().getPath(getHome()),"system-config",".properties");
+
+                ((PropertiesConfiguration) saveConfiguration).save(tmpFile.toFile());
+
+                Files.move(tmpFile, FileSystems.getDefault().getPath(configFileName), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE);
+            } catch (ConfigurationException | IOException e) {
                 log.error("could not save system configuration: #0", e.getMessage());
             }
         }
 
         if(saveMetadata instanceof PropertiesConfiguration) {
             try {
-                ((PropertiesConfiguration)saveMetadata).save();
-            } catch (ConfigurationException e) {
+                Path tmpFile = Files.createTempFile(FileSystems.getDefault().getPath(getHome()),"system-meta",".properties");
+
+                ((PropertiesConfiguration)saveMetadata).save(tmpFile.toFile());
+
+
+                Files.move(tmpFile, FileSystems.getDefault().getPath(metaFileName), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE);
+            } catch (ConfigurationException | IOException e) {
                 log.error("could not save system metadata: #0", e.getMessage());
             }
         }


Mime
View raw message