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 <gpe@openrs2.org>
Graham 3 years ago
parent f7e194dfa6
commit 21560b1afd
  1. 10
      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 <T> 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
}
}

Loading…
Cancel
Save