From 06b6f845e899fd1e23a2dfe54ec8debfe55b807b Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 13 Aug 2021 18:00:54 -0400 Subject: [PATCH] config manager: fsync temp config file --- .../net/runelite/client/config/ConfigManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java b/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java index 7e66bb0fdc..f06319c68f 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java +++ b/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java @@ -44,6 +44,7 @@ import java.io.OutputStreamWriter; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; +import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; import java.nio.file.AtomicMoveNotSupportedException; import java.nio.file.Files; @@ -374,11 +375,14 @@ public class ConfigManager File tempFile = File.createTempFile("runelite", null, parent); - try (FileOutputStream out = new FileOutputStream(tempFile)) + try (FileOutputStream out = new FileOutputStream(tempFile); + FileChannel channel = out.getChannel(); + OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { - out.getChannel().lock(); - properties.store(new OutputStreamWriter(out, StandardCharsets.UTF_8), "RuneLite configuration"); - // FileOutputStream.close() closes the associated channel, which frees the lock + channel.lock(); + properties.store(writer, "RuneLite configuration"); + channel.force(true); + // FileChannel.close() frees the lock } try