Recently I’ve seen a couple of cases where users have ended up with corrupted files — almost always in relation to a plugin crashing coincidentally at the same time the song, rack or settings file was being written.
The result is a half written file that can’t be read back.
To mitigate against this, Cantabile now writes all JSON files atomically — that is it’s either an all or nothing result. This applies to Cantabile’s settings file, song and rack files, set lists and a few other files.
How it Works
The approach used for writing JSON files is pretty simple — its saves the file first with an extra .tmp file extension and then renames it afterwards.
Suppose it’s saving MySong.CantabileSong it will:
- Write a file called MySong.CantabileSong.tmp
- Wait for it to be successfully written and flushed
- Delete the old MySong.CantabileSong file
- Rename MySong.CantabileSong.tmp to MySong.CantabileSong
The worst case scenario now is if it crashes between steps 3 and 4. In that case you’re song file will be missing, but an updated version will be available in the .tmp file if you need to recover it.
This will be available in build 3239.