From d718b0b34eda84744778fa12a01d5be5f03753d3 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Tue, 13 Aug 2013 19:15:06 +0200 Subject: Dont write directly to files but rather write and copy a tmp file --- src/map.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index da20b5b0e..331aa48d9 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3490,20 +3490,21 @@ void ServerMap::saveMapMeta() createDirs(m_savedir); std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt"; - std::ofstream os(fullpath.c_str(), std::ios_base::binary); - if(os.good() == false) - { - infostream<<"ERROR: ServerMap::saveMapMeta(): " - <<"could not open"<setParamsToSettings(¶ms); - params.writeLines(os); + params.writeLines(ss); - os<<"[end_of_params]\n"; + ss<<"[end_of_params]\n"; + + if(!fs::safeWriteToFile(fullpath, ss.str())) + { + infostream<<"ERROR: ServerMap::saveMapMeta(): " + <<"could not write "<serialize(ss, version); - sector->serialize(o, version); + if(!fs::safeWriteToFile(fullpath, ss.str())) + throw FileNotGoodException("Cannot write sector metafile"); sector->differs_from_disk = false; } -- cgit v1.2.3