Index: base/files/important_file_writer.cc |
diff --git a/base/files/important_file_writer.cc b/base/files/important_file_writer.cc |
index c996da23a1501f2fbe2f18af2e1e585ea9153aed..d7579abb112432f8e97be4a81d5c6b1ea1c484ba 100644 |
--- a/base/files/important_file_writer.cc |
+++ b/base/files/important_file_writer.cc |
@@ -33,6 +33,7 @@ enum TempFileFailure { |
FAILED_CLOSING, |
FAILED_WRITING, |
FAILED_RENAMING, |
+ FAILED_FLUSHING, |
TEMP_FILE_FAILURE_MAX |
}; |
@@ -69,7 +70,7 @@ bool ImportantFileWriter::WriteFileAtomically(const FilePath& path, |
CHECK_LE(data.length(), static_cast<size_t>(kint32max)); |
int bytes_written = tmp_file.Write(0, data.data(), |
static_cast<int>(data.length())); |
- tmp_file.Flush(); // Ignore return value. |
+ bool flush_success = tmp_file.Flush(); |
tmp_file.Close(); |
if (bytes_written < static_cast<int>(data.length())) { |
@@ -79,6 +80,12 @@ bool ImportantFileWriter::WriteFileAtomically(const FilePath& path, |
return false; |
} |
+ if (!flush_success) { |
+ LogFailure(path, FAILED_FLUSHING, "error flushing"); |
+ base::DeleteFile(tmp_file_path, false); |
+ return false; |
+ } |
+ |
if (!base::ReplaceFile(tmp_file_path, path, NULL)) { |
LogFailure(path, FAILED_RENAMING, "could not rename temporary file"); |
base::DeleteFile(tmp_file_path, false); |