]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
AtomicFile: Cope with write error (e.g. due to full disk) when closing
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 1 Nov 2019 20:24:55 +0000 (21:24 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 1 Nov 2019 21:24:02 +0000 (22:24 +0100)
src/AtomicFile.cpp

index 6661c022d6b6271a1868ea004e2c40c3a1d137c4..9ad351764407f3b041c7cfbf1528dcda82948001 100644 (file)
@@ -66,8 +66,13 @@ void
 AtomicFile::commit()
 {
   assert(m_stream);
-  fclose(m_stream);
+  int result = fclose(m_stream);
   m_stream = nullptr;
+  if (result == EOF) {
+    tmp_unlink(m_tmp_path.c_str());
+    throw Error(
+      fmt::format("failed to write data to {}: {}", m_path, strerror(errno)));
+  }
   if (x_rename(m_tmp_path.c_str(), m_path.c_str()) != 0) {
     throw Error(fmt::format("failed to rename {} to {}", m_tmp_path, m_path));
   }