From 21560b1afd82b76280bf864b9c4039c0f1d76eff Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 7 May 2022 22:12:15 +0100 Subject: [PATCH] Ignore fsync on directory failures It isn't supported on some platforms, so there's not much we can do if it does fail. Signed-off-by: Graham --- .../main/kotlin/org/openrs2/util/io/PathExtensions.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/src/main/kotlin/org/openrs2/util/io/PathExtensions.kt b/util/src/main/kotlin/org/openrs2/util/io/PathExtensions.kt index 839fb7ed..24645469 100644 --- a/util/src/main/kotlin/org/openrs2/util/io/PathExtensions.kt +++ b/util/src/main/kotlin/org/openrs2/util/io/PathExtensions.kt @@ -1,6 +1,7 @@ package org.openrs2.util.io import java.io.BufferedWriter +import java.io.IOException import java.io.OutputStream import java.nio.channels.FileChannel import java.nio.charset.Charset @@ -110,8 +111,15 @@ public inline fun Path.atomicWrite(f: (Path) -> T): T { parent.useTempFile(".$fileName", ".tmp") { tempFile -> val result = f(tempFile) tempFile.fsync() + Files.move(tempFile, this, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING) - parent.fsync() + + try { + parent.fsync() + } catch (ex: IOException) { + // can't fsync directories on (at least) Windows and jimfs + } + return result } }