mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-12 16:15:20 +02:00
Remove temporary file at safeWriteToFile()
This commit is contained in:
@@ -701,16 +701,19 @@ bool safeWriteToFile(const std::string &path, const std::string &content)
|
|||||||
os << content;
|
os << content;
|
||||||
os.flush();
|
os.flush();
|
||||||
os.close();
|
os.close();
|
||||||
if (os.fail())
|
if (os.fail()) {
|
||||||
|
remove(tmp_file.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy file
|
// Copy file
|
||||||
#ifdef _WIN32
|
|
||||||
remove(path.c_str());
|
remove(path.c_str());
|
||||||
return (rename(tmp_file.c_str(), path.c_str()) == 0);
|
if(rename(tmp_file.c_str(), path.c_str())) {
|
||||||
#else
|
remove(tmp_file.c_str());
|
||||||
return (rename(tmp_file.c_str(), path.c_str()) == 0);
|
return false;
|
||||||
#endif
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fs
|
} // namespace fs
|
||||||
|
Reference in New Issue
Block a user