I use <kotlinx.io> and after writing a file I call...
# io
t
I use kotlinx.io and after writing a file I call flush(). However, if the computer the code runs on switches off without proper shutdown, the file contains zeroes after the reboot. According to JVM OutputStream docs flush() guarantees that the data is passed to the operating system but it doesn't guarantee that it is actually written out. Are there any good solutions for this apart implementing my own functions to write files?
e
there's no good solutions even if you implement your own functions
t
The FileChannel has a force(true), the description says that it does guarantee that the OS writes out the data (raid cache and other stuff like that is a different matter).
e
thank you color 1
t
Thanks, fdatasync looks good actually. Maybe I'll just implement the file write for JVM manually.
e
Linux's guarantees on fdatasync are different than other OSes (that's why Java calls fsync either way (but it needs a different solution for macos to be accurate))
t
Ah, I get it, thanks. My main target is Linux, so this might be quite OK. The problem doesn't really exists on Mac OS as this is about data collecting systems running on the field.
e
also see https://danluu.com/fsyncgate/ (and https://lwn.net/Articles/667788/ discussion) - if any sync fails, you're kinda screwed since there isn't any way to determine what to do next in POSIX
thank you color 1