From: selat Date: Sun, 13 Jul 2014 20:35:29 +0000 (+0300) Subject: Remove temporary file at safeWriteToFile() X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=5f1f1151d3a9c113902630adc16cc3f4845da7ba;p=zefram%2Fminetest%2Fminetest_engine.git Remove temporary file at safeWriteToFile() --- diff --git a/src/filesys.cpp b/src/filesys.cpp index 7c72a4b2..b95986a9 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