1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-08-13 16:53:49 -04:00

Remove temporary file at safeWriteToFile()

This commit is contained in:
selat 2014-07-13 23:35:29 +03:00 committed by sapier
parent f6e01adab7
commit 5f1f1151d3

View File

@ -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