1 (edited by catpaw 2008-05-17 15:05:57)

Topic: editor save safety

Please apply this patch, in this case the map save will NEVER destroy your existing file, if failing out of whaever reason (segfault, killed -9, powerfailure during save, whatever)

I don't know if "unistd.h" is available on windows, if not just leave the sync() away, its just some extra safety. Rename is part of stdio.h so there is sure no OS problems.

Thankyou.
-------------------------------------------------------------------------------------------------------------
--- src.org/game/editor/ed_io.cpp       2008-05-17 15:05:31.000000000 +0200
+++ src/game/editor/ed_io.cpp   2008-05-17 15:20:21.000000000 +0200
@@ -1,5 +1,6 @@
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
#include "ed_editor.hpp"

template<typename T>
@@ -195,11 +196,15 @@

int MAP::save(const char *filename)
{
-       dbg_msg("editor", "saving to '%s'...", filename);
-       DATAFILE_OUT *df = datafile_create(filename);
+       static char save_tmp_filename[512] = {0};
+       strncpy(save_tmp_filename, filename, sizeof(save_tmp_filename));
+       strncat(save_tmp_filename, ".tmp",  sizeof(save_tmp_filename));
+
+       dbg_msg("editor", "saving to '%s'...", save_tmp_filename);
+       DATAFILE_OUT *df = datafile_create(save_tmp_filename);
        if(!df)
        {
-               dbg_msg("editor", "failed to open file '%s'...", filename);
+               dbg_msg("editor", "failed to open file '%s'...", save_tmp_filename);
                return 0;
        }

@@ -345,7 +350,13 @@
        // finish the data file
        datafile_finish(df);
        dbg_msg("editor", "done");
-
+
+       sync();
+       if (rename(save_tmp_filename, filename)) {
+               dbg_msg("editor", "failed to rename file '%s'...", save_tmp_filename);
+               return 0;
+       }
+
        // send rcon.. if we can
        if(client_rcon_authed())
        {
-------------------------------------------------------

2

Re: editor save safety

As general tip @package mantainer, if someone makes the work to provide a real patch, whatever you do. Do not just ignore it. Say have it already, don't need it, not a good idea, or whatever, but don't just ignore it.

/me is now pretty much miffed. Don't expect any more code offers in near future.

3

Re: editor save safety

I am on linux how can can I apply this patch ?

4

Re: editor save safety

catpaw wrote:

As general tip @package mantainer, if someone makes the work to provide a real patch, whatever you do. Do not just ignore it. Say have it already, don't need it, not a good idea, or whatever, but don't just ignore it.

/me is now pretty much miffed. Don't expect any more code offers in near future.

yes.... here are so much people who just want to help this project in some way and there is very often no reaction. i can totally understand you, catpaw.


@ubuntu change to the teeworlds source directory and write "patch the_quoted_patch.patch". then compile it again.

5 (edited by shmafoozius 2008-06-17 08:20:13)

Re: editor save safety

I'm almost thinking making some community patch would be much more of use, than just making suggestions and getting no feedback for it at all. tongue

bam: WARNING:'src/game/server/gamemodes/mod.cpp' comes from the future

6

Re: editor save safety

http://catb.org/~esr/writings/cathedral … al-bazaar/

7

Re: editor save safety

I appreciate your work. Keep on working smile
But keep in mind that the devs do not have a lot of time. Even if it is frustrating to you. :-/

Antoine de Saint Exupéry: It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away.
Besides -  I am the gfx guy!

8 (edited by Chi11y 2008-06-18 11:45:37)

Re: editor save safety

Teeworlds needs a more open way of developing, atm matricks is almost the only one who can commit to svn, which makes developing slow, the advantages of open source should be used in a better manner imho.


Oh, btw great patch! smile

Official Teeworlds map developer and community moderator
Administrator for the Teeworlds community Teesites

9

Re: editor save safety

The idea of this patch is great, but it's pretty useless on windows systems (not because of the unistd.h thingy), since it can't rename the map when some server is running it. I'd suggest to make a _copy_ of the map instead of renaming it, and adding the crc in the filename (like the client does after map transfer), or just adding something else to the filename. I added the current time in my version so I get a different backup each time I'm saving the map, which is - in my opinion - pretty usefull.

Btw, your patch made me working on the Editor some more and I now can easily add kind of animated tiles to my map. ^^ Thanks for making me look at the source code. big_smile

bam: WARNING:'src/game/server/gamemodes/mod.cpp' comes from the future