@gstavi ,
Good points.
I hope you indeed fixed ALL the races
I did. Those related to periodic backups.
I am not convinced about disk caching explanation because this should have made it a common problem for lots of application.
It is apparently a common problem for other applications too.
Here is another debate on the topic:
https://community.notepad-plus-plus.org/post/48725
Your patch looks good but to avoid the disk caching problems you need to use FILE_FLAG_WRITE_THROUGH (or in your used Win API it should be _WRITE_THROUGH, I’m not sure) when creating/opening the files.
As I’ve written before in several places the problems are two:
fopen erases file contents on open with write permissions. This is causing the “no-space on disk” file contents loss problem and perhaps the problem you have encountered and are mentioning here.
File contents loss on reboot/power loss (even when files are edited and saved) are caused by disk write caching (defined by Microsoft as “lazy writer” in some of their documents).
Perhaps a combination of reasons will convince @donho at some point.
I doubt it. A lot of people (including me) had given him a lot of reasons already including the root cause of the problems and a possible fix.
Do remember it if you ever choose to fix the out-of-space bug by creating a new file
I though about it in the beginning when I was trying to figure out the cause of the write issues.
In my PR I actually use native Win32 file handling API as you do in your patch to avoid the fopen file contents erasure. There is no need to create new file in that case - forget that I mentioned it (it was just a possible and sub-optimal workaround to the first problem I gave above).