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())
{
-------------------------------------------------------