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/environment.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/environment.cpp') diff --git a/src/environment.cpp b/src/environment.cpp index 35983aaaf..eacc2a008 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -437,13 +437,13 @@ void ServerEnvironment::serializePlayers(const std::string &savedir) if(player->checkModified()) { // Open file and serialize - std::ofstream os(path.c_str(), std::ios_base::binary); - if(os.good() == false) + std::ostringstream ss(std::ios_base::binary); + player->serialize(ss); + if(!fs::safeWriteToFile(path, ss.str())) { - infostream<<"Failed to overwrite "<serialize(os); saved_players.insert(player); } else { saved_players.insert(player); @@ -493,13 +493,13 @@ void ServerEnvironment::serializePlayers(const std::string &savedir) /*infostream<<"Saving player "<getName()<<" to " <serialize(ss); + if(!fs::safeWriteToFile(path, ss.str())) { - infostream<<"Failed to overwrite "<serialize(os); saved_players.insert(player); } } @@ -581,19 +581,20 @@ void ServerEnvironment::saveMeta(const std::string &savedir) std::string path = savedir + "/env_meta.txt"; // Open file and serialize - std::ofstream os(path.c_str(), std::ios_base::binary); - if(os.good() == false) - { - infostream<<"ServerEnvironment::saveMeta(): Failed to open " - <