News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

Always save games to a temporary file first

Started by ACarlotti, September 24, 2018, 12:50:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ACarlotti

This patch is a response to the problems encountered with a Simutrans Extended server (discussed here); namely that a memory leak was causing the server to be killed midway through saving the game, resulting in a catastrophic loss of save data. This loss of data could have been avoided if the saves were written to a separate file before being renamed to replace the previous save file (of the same name).

The patch modifies karte_t::save to always write first to a temporary file. It also changes the name of the temporary file to be the original file name with ".part" appended to avoid corruption or loss of data if two different instances of Simutrans are saving games simulataneously.

prissi

I do not get why appending .part. _temp.sve or replacing the last four letters by sv_ could be used and will not lead into troubles should appending .part make a too long filename for that system. Otherwise very useful. Incorporated in r8602, thanks

ACarlotti

Quote from: prissi on September 24, 2018, 02:19:51 PMI do not get why appending .part.

That was based upon the approach I have seen when downloading files from a web browser, where during the download the filename for the partial file has ".download" appended. I hadn't thought of filename length limits, however, and I think .sv_ is a better choice.