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/serverlist.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/serverlist.cpp')
-rw-r--r-- | src/serverlist.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/serverlist.cpp b/src/serverlist.cpp index bc09f6c0a..4db5f3ecd 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -105,13 +105,11 @@ bool deleteEntry (ServerListSpec server) } std::string path = ServerList::getFilePath(); - std::ofstream stream (path.c_str()); - if (stream.is_open()) - { - stream<<ServerList::serialize(serverlist); - return true; - } - return false; + std::ostringstream ss(std::ios_base::binary); + ss << ServerList::serialize(serverlist); + if (!fs::safeWriteToFile(path, ss.str())) + return false; + return true; } /* @@ -128,11 +126,9 @@ bool insert (ServerListSpec server) serverlist.insert(serverlist.begin(), server); std::string path = ServerList::getFilePath(); - std::ofstream stream (path.c_str()); - if (stream.is_open()) - { - stream<<ServerList::serialize(serverlist); - } + std::ostringstream ss(std::ios_base::binary); + ss << ServerList::serialize(serverlist); + fs::safeWriteToFile(path, ss.str()); return false; } |