From 7179743f5d539126c73a02055fe6f9d3c465ff46 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 18 Aug 2020 17:34:40 +0100 Subject: [PATCH] Add fsync() extension method Signed-off-by: Graham --- .../main/java/dev/openrs2/util/io/PathExtensions.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/src/main/java/dev/openrs2/util/io/PathExtensions.kt b/util/src/main/java/dev/openrs2/util/io/PathExtensions.kt index 580e54fb..a6565a8b 100644 --- a/util/src/main/java/dev/openrs2/util/io/PathExtensions.kt +++ b/util/src/main/java/dev/openrs2/util/io/PathExtensions.kt @@ -2,13 +2,23 @@ package dev.openrs2.util.io import java.io.BufferedWriter import java.io.OutputStream +import java.nio.channels.FileChannel import java.nio.charset.Charset import java.nio.file.Files import java.nio.file.OpenOption import java.nio.file.Path import java.nio.file.StandardCopyOption +import java.nio.file.StandardOpenOption import java.nio.file.attribute.FileAttribute +fun Path.fsync() { + require(Files.isRegularFile(this) || Files.isDirectory(this)) + + FileChannel.open(this, StandardOpenOption.READ).use { channel -> + channel.force(true) + } +} + inline fun useTempFile( prefix: String? = null, suffix: String? = null,