aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorselat <longexampletestname@gmail.com>2014-07-13 23:35:29 +0300
committersapier <Sapier at GMX dot net>2014-08-16 12:46:48 +0200
commit5f1f1151d3a9c113902630adc16cc3f4845da7ba (patch)
tree4b98f9dbb6767b64a02fb72ec2a68af13b5140d9
parentf6e01adab7ed2adbdc8f07b855d1ae4669c607c9 (diff)
downloadminetest-5f1f1151d3a9c113902630adc16cc3f4845da7ba.tar.gz
minetest-5f1f1151d3a9c113902630adc16cc3f4845da7ba.tar.bz2
minetest-5f1f1151d3a9c113902630adc16cc3f4845da7ba.zip
Remove temporary file at safeWriteToFile()
-rw-r--r--src/filesys.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/filesys.cpp b/src/filesys.cpp
index 7c72a4b27..b95986a92 100644
--- a/src/filesys.cpp
+++ b/src/filesys.cpp
@@ -701,16 +701,19 @@ bool safeWriteToFile(const std::string &path, const std::string &content)
os << content;
os.flush();
os.close();
- if (os.fail())
+ if (os.fail()) {
+ remove(tmp_file.c_str());
return false;
+ }
// Copy file
-#ifdef _WIN32
remove(path.c_str());
- return (rename(tmp_file.c_str(), path.c_str()) == 0);
-#else
- return (rename(tmp_file.c_str(), path.c_str()) == 0);
-#endif
+ if(rename(tmp_file.c_str(), path.c_str())) {
+ remove(tmp_file.c_str());
+ return false;
+ } else {
+ return true;
+ }
}
} // namespace fs