protect against data loss in the event of a system crash shortly after saving
the file.
Previously, there was a problem with modern Linux filesystems like ext4,
which could lead to a zero-length project file after a crash. For details,
see here[1].
Instead of writing a backup copy and then overwriting the original file, we
now follow the procedure given in [2]:
1) save the new file as <filename>.new
2) make sure data is actually written to disk (fsync)
3) rename <filename> to <filename>~ (keep backup copy)
4) rename <filename>.new to <filename>
Note that the newly written data can still be lost by a system crash with
some bad luck, because changes to the directory containing the file aren't
synced. However, seeing that working on a project happens in memory most of
the time, there'll always be plenty of chances for a system crash to cause
data loss. The point of the above change is rather that after a system crash,
either the old or the new version of the file should be on disk, so you loose
at most the work done since the last saved state. This is also what Vim, Emacs
and other applications do.
[1] http://beta.linuxfoundation.org/news-media/blogs/browse/2009/03/don’t-fear-fsync
[2] http://bugs.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/54