aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-athenz
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-08-09 12:54:24 +0200
committerBjørn Christian Seime <bjorncs@oath.com>2018-08-09 12:54:28 +0200
commit0e00a548dcd671cd5a73038091d870d52dd13f7e (patch)
tree036e2e23dede2f9fe5a0a51e7de555c35896e821 /vespa-athenz
parent3f6413b7293142a97c7423d276c44595d2f30a2d (diff)
Write identity document to temp file, then atomic move
Diffstat (limited to 'vespa-athenz')
-rw-r--r--vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
index 3bfe492a125..641c3001795 100644
--- a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
+++ b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
@@ -11,7 +11,10 @@ import com.yahoo.vespa.athenz.identityprovider.api.bindings.VespaUniqueInstanceI
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.Base64;
import static com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId.fromDottedString;
@@ -116,7 +119,9 @@ public class EntityBindingsMapper {
public static void writeSignedIdentityDocumentToFile(Path file, SignedIdentityDocument document) {
try {
SignedIdentityDocumentEntity entity = EntityBindingsMapper.toSignedIdentityDocumentEntity(document);
- mapper.writeValue(file.toFile(), entity);
+ Path tempFile = Paths.get(file.toAbsolutePath().toString() + ".tmp");
+ mapper.writeValue(tempFile.toFile(), entity);
+ Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
throw new UncheckedIOException(e);
}