]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Add AtomicFile::flush method
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 3 Dec 2022 12:33:33 +0000 (13:33 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Dec 2022 19:38:37 +0000 (20:38 +0100)
src/AtomicFile.cpp
src/AtomicFile.hpp

index c9d82c3e2728a2599fdf1499d455598b550889e1..9c0f0cb3cb5104e62f575a281849f93a04933703 100644 (file)
@@ -59,6 +59,15 @@ AtomicFile::write(nonstd::span<const uint8_t> 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()
 {
index 37ac37228557e548cad65d9e28fccede337318f5..033a3fa3c92eae326e849caee7e04277d1d9812a 100644 (file)
@@ -38,6 +38,7 @@ public:
 
   void write(std::string_view data);
   void write(nonstd::span<const uint8_t> 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