honestbleeps/Reddit-Enhancement-Suite — pull request #934 by CyberShadow (2014-04-13 03:39:23+00:00)
Title: Save to store.json.tmp before overwriting to store.json.

This should greatly decrease chances of data corruption, at least on NTFS.

Previously, there existed a window during which not all data existed on disk. Reopening the file with the "w" mode would truncate it, meaning that for some time the user data did not exist on the filesystem.

This patch makes the save operation atomic - since the data is written to a temporary file first, and overwriting files by renames is an atomic operation, saving data should be much safer with this change.