diff options
author | PilzAdam <pilzadam@minetest.net> | 2013-08-13 19:15:06 +0200 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-08-13 22:05:45 +0200 |
commit | d718b0b34eda84744778fa12a01d5be5f03753d3 (patch) | |
tree | 6ee450e7f1078a114c71f73ead16310f13bbc00c /src/map.cpp | |
parent | c8930850e37dab9820049152a3e668a315a97560 (diff) | |
download | minetest-d718b0b34eda84744778fa12a01d5be5f03753d3.tar.gz minetest-d718b0b34eda84744778fa12a01d5be5f03753d3.tar.bz2 minetest-d718b0b34eda84744778fa12a01d5be5f03753d3.zip |
Dont write directly to files but rather write and copy a tmp file
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
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"<<fullpath<<std::endl; - throw FileNotGoodException("Cannot open chunk metadata"); - } + std::ostringstream ss(std::ios_base::binary); Settings params; m_emerge->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 "<<fullpath<<std::endl; + throw FileNotGoodException("Cannot save chunk metadata"); + } m_map_metadata_changed = false; } @@ -3574,11 +3575,12 @@ void ServerMap::saveSectorMeta(ServerMapSector *sector) createDirs(dir); std::string fullpath = dir + DIR_DELIM + "meta"; - std::ofstream o(fullpath.c_str(), std::ios_base::binary); - if(o.good() == false) - throw FileNotGoodException("Cannot open sector metafile"); + std::ostringstream ss(std::ios_base::binary); + + sector->serialize(ss, version); - sector->serialize(o, version); + if(!fs::safeWriteToFile(fullpath, ss.str())) + throw FileNotGoodException("Cannot write sector metafile"); sector->differs_from_disk = false; } |