mirror of
https://github.com/XRPLF/clio.git
synced 2026-02-08 16:02:28 +00:00
fix: Flush buffers before renaming cache file (#2927)
If clio shuts itself down due to exceeding graceful period when cache is saved and renamed but the buffers are not flushed, we may end up with a corrupted cache file. Clio will detect corruption and will not load corrupted cache file, but we could avoid it by explicitly flushing ofstream buffer.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <expected>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -59,4 +60,14 @@ OutputFile::hash() const
|
||||
return std::move(sum).finalize();
|
||||
}
|
||||
|
||||
std::expected<void, std::string>
|
||||
OutputFile::close()
|
||||
{
|
||||
file_.close();
|
||||
if (not file_) {
|
||||
return std::unexpected{"Error closing cache file"};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace data::impl
|
||||
|
||||
Reference in New Issue
Block a user