c++ - Atomic writes with respect to unexpected power offs -


i have ~100kb-long file overwritten every few minutes single writer operator << on std::ofstream. want avoid kind of "partial writing" situations might caused system being powered off while file being flushed disk. want in software as os/posix permits.

my idea use overwrite-by-rename strategy, flush() data temporary filename, rename temporary filename final filename.

my question if strategy, in sense atomicity on renaming guaranteed posix os (e.g. linux) or have better ideas (which not involve hardware modifications , possibly no fs flag modifications @ kernel/system level)

if don't trust atomicity of rename - , can't in case of crash non-journaling filesystem - first rename original file temporary name, rename new file original name, , remove original file, temporary name. way, if crash occurs, @ least 1 of 3 filepaths not under modification.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -