diff options
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; } |