Call fsync() when close file descriptor am: 3dd8397941 am: c7939fa8fe am: 1ec7764cae am: f4e3c28828
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1462862
Change-Id: I64a2bb305299ee2f0d545b9d3a31833b12879760
diff --git a/payload_consumer/file_descriptor.cc b/payload_consumer/file_descriptor.cc
index 1de615c..6101c68 100644
--- a/payload_consumer/file_descriptor.cc
+++ b/payload_consumer/file_descriptor.cc
@@ -21,6 +21,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <unistd.h>
#include <base/posix/eintr_wrapper.h>
@@ -125,11 +126,16 @@
bool EintrSafeFileDescriptor::Flush() {
CHECK_GE(fd_, 0);
+ // Implemented as a No-Op, as delta_performer typically uses |O_DSYNC|, except
+ // in interactive settings.
return true;
}
bool EintrSafeFileDescriptor::Close() {
CHECK_GE(fd_, 0);
+ // https://stackoverflow.com/questions/705454/does-linux-guarantee-the-contents-of-a-file-is-flushed-to-disc-after-close
+ // |close()| doesn't imply |fsync()|, we need to do it manually.
+ fsync(fd_);
if (IGNORE_EINTR(close(fd_)))
return false;
fd_ = -1;