Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1130)

Unified Diff: base/files/important_file_writer.cc

Issue 663463002: Abort ImportantFileWriter::WriteFileAtomically() on Flush() error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-order error handling. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698