From: Joel Rosdahl Date: Fri, 1 Nov 2019 20:24:55 +0000 (+0100) Subject: AtomicFile: Cope with write error (e.g. due to full disk) when closing X-Git-Tag: v4.0~716 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1b4703dca89c18a91edc57e1200f12982dd340e;p=thirdparty%2Fccache.git AtomicFile: Cope with write error (e.g. due to full disk) when closing --- diff --git a/src/AtomicFile.cpp b/src/AtomicFile.cpp index 6661c022d..9ad351764 100644 --- a/src/AtomicFile.cpp +++ b/src/AtomicFile.cpp @@ -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)); }