mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-03 08:46:42 +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:
@@ -115,6 +115,11 @@ LedgerCacheFile::write(DataView dataView)
|
||||
auto const hash = file.hash();
|
||||
file.write(hash.data(), decltype(hash)::bytes);
|
||||
|
||||
// flush internal buffer explicitly before renaming
|
||||
if (auto const expectedSuccess = file.close(); not expectedSuccess.has_value()) {
|
||||
return expectedSuccess;
|
||||
}
|
||||
|
||||
try {
|
||||
std::filesystem::rename(newFilePath, path_);
|
||||
} catch (std::exception const& e) {
|
||||
|
||||
Reference in New Issue
Block a user