The International Simutrans Forum

 

Author Topic: Always save games to a temporary file first  (Read 276 times)

0 Members and 1 Guest are viewing this topic.

Offline ACarlotti

  • *
  • Posts: 299
Always save games to a temporary file first
« on: September 24, 2018, 12:50:44 PM »
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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9353
  • Languages: De,EN,JP
Re: Always save games to a temporary file first
« Reply #1 on: September 24, 2018, 02:19:51 PM »
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

Offline ACarlotti

  • *
  • Posts: 299
Re: Always save games to a temporary file first
« Reply #2 on: September 24, 2018, 11:06:07 PM »
I 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.