MegaAntiCheat / client-backend

GNU General Public License v3.0
117 stars 24 forks source link

Use AtomicWriteFile to prevent possible data corruption #123

Closed Bash-09 closed 5 months ago

Bash-09 commented 5 months ago

Previously it was not guaranteed to be safe to just quit the app with Ctrl C as it might be possible to time it to kill the app while it was attempting to write out the config or playerlist files (resulting in corruption), but there was also no clean way to shutdown the app.

Such an occurrence of corruption should be extremely unlikely, but probably still possible. A discord thread reported their playerlist and settings files being corrupted. I'm not 100% sure if it was because of the reason mentioned above (as I would have expected at most one of these files to be corrupted), but it's still a good indication we should be more careful about this.

I've just made a small change which uses the atomic-write-file crate to guarantee the files are either successfully written out in their entirety or not overwritten at all, so they should never be able to end up in an inconsistent state.