From: Joel Rosdahl Date: Sat, 3 Dec 2022 12:33:33 +0000 (+0100) Subject: enhance: Add AtomicFile::flush method X-Git-Tag: v4.8~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=beb5a3db5eb9105ea5a28c814c37be788f5feab4;p=thirdparty%2Fccache.git enhance: Add AtomicFile::flush method --- diff --git a/src/AtomicFile.cpp b/src/AtomicFile.cpp index c9d82c3e2..9c0f0cb3c 100644 --- a/src/AtomicFile.cpp +++ b/src/AtomicFile.cpp @@ -59,6 +59,15 @@ AtomicFile::write(nonstd::span data) } } +void +AtomicFile::flush() +{ + if (fflush(m_stream) != 0) { + throw core::Error( + FMT("failed to flush data to {}: {}", m_path, strerror(errno))); + } +} + void AtomicFile::commit() { diff --git a/src/AtomicFile.hpp b/src/AtomicFile.hpp index 37ac37228..033a3fa3c 100644 --- a/src/AtomicFile.hpp +++ b/src/AtomicFile.hpp @@ -38,6 +38,7 @@ public: void write(std::string_view data); void write(nonstd::span data); + void flush(); // Close the temporary file and rename it to the destination file. Note: The // destructor will not do this automatically to avoid half-written data in the