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/ban.cpp | |
parent | c8930850e37dab9820049152a3e668a315a97560 (diff) | |
download | hax-minetest-server-d718b0b34eda84744778fa12a01d5be5f03753d3.tar.gz hax-minetest-server-d718b0b34eda84744778fa12a01d5be5f03753d3.zip |
Dont write directly to files but rather write and copy a tmp file
Diffstat (limited to 'src/ban.cpp')
-rw-r--r-- | src/ban.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ban.cpp b/src/ban.cpp index 75bae746f..f9d32b605 100644 --- a/src/ban.cpp +++ b/src/ban.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <set> #include "strfnd.h" #include "log.h" +#include "filesys.h" BanManager::BanManager(const std::string &banfilepath): m_banfilepath(banfilepath), @@ -76,20 +77,20 @@ void BanManager::save() { JMutexAutoLock lock(m_mutex); infostream<<"BanManager: saving to "<<m_banfilepath<<std::endl; - std::ofstream os(m_banfilepath.c_str(), std::ios::binary); - - if(os.good() == false) - { - infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl; - throw SerializationError("BanManager::load(): Couldn't open file"); - } + std::ostringstream ss(std::ios_base::binary); for(std::map<std::string, std::string>::iterator i = m_ips.begin(); i != m_ips.end(); i++) { - os<<i->first<<"|"<<i->second<<"\n"; + ss << i->first << "|" << i->second << "\n"; } + + if(!fs::safeWriteToFile(m_banfilepath, ss.str())) { + infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl; + throw SerializationError("BanManager::load(): Couldn't write file"); + } + m_modified = false; } |