With the current code, it's possible to end up with a zero-size
persistence file (or even corruption of the contents) if the
process gets killed or the system takes a power outage.
Switch to a "write to temp file and rename" model for writing the
persistence file. This will make it more robust against unclean
process termination or unclean system shutdown.
Change-Id: Ic4fdb5a9f6f622b2ab9658f7d4206e4c8ca55046
Closes-Bug: #1499795