mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Dont write directly to files but rather write and copy a tmp file
This commit is contained in:
parent
c8930850e3
commit
d718b0b34e
9 changed files with 101 additions and 69 deletions
17
src/ban.cpp
17
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue