Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/data/impl/LedgerCacheFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/data/impl/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <cstddef>
#include <cstring>
#include <expected>
#include <ios>
#include <string>
#include <utility>
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/data/impl/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cstddef>
#include <cstring>
#include <expected>
#include <fstream>
#include <string>

Expand Down Expand Up @@ -60,6 +61,9 @@ class OutputFile {
ripple::uint256
hash() const;

std::expected<void, std::string>
close();

private:
void
writeToFile(char const* data, size_t size);
Expand Down
Loading