config manager: fsync temp config file

This commit is contained in:
Adam
2021-08-13 18:00:54 -04:00
parent 8fa085f4f9
commit 06b6f845e8

View File

@@ -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