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/settings.h | |
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/settings.h')
-rw-r--r-- | src/settings.h | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/settings.h b/src/settings.h index e7b49b6d7..a9e0faa40 100644 --- a/src/settings.h +++ b/src/settings.h @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <list> #include <map> #include <set> +#include "filesys.h" enum ValueType { @@ -308,14 +309,7 @@ public: // Write stuff back { - std::ofstream os(filename); - if(os.good() == false) - { - errorstream<<"Error opening configuration file" - " for writing: \"" - <<filename<<"\""<<std::endl; - return false; - } + std::ostringstream ss(std::ios_base::binary); /* Write updated stuff @@ -324,7 +318,7 @@ public: i = objects.begin(); i != objects.end(); ++i) { - os<<(*i); + ss<<(*i); } /* @@ -340,7 +334,14 @@ public: std::string value = i->second; infostream<<"Adding \""<<name<<"\" = \""<<value<<"\"" <<std::endl; - os<<name<<" = "<<value<<"\n"; + ss<<name<<" = "<<value<<"\n"; + } + + if(!fs::safeWriteToFile(filename, ss.str())) + { + errorstream<<"Error writing configuration file: \"" + <<filename<<"\""<<std::endl; + return false; } } |