update_engine: Add Flush() to FileDescriptor

This patch adds Flush() function to the file descriptor. This function
should be called after each operation in order to ensure that data
resides to disk before any checkpointing happen. In addition, if any
future file descriptor that caches the data is added, this ensures
integrity of written data.

BUG=chromium:762815
TEST=brillo_update_payload verify

Change-Id: I12442142647605afef1b01dc932eb7cf182af85b
Reviewed-on: https://chromium-review.googlesource.com/674163
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/payload_consumer/file_descriptor.h b/payload_consumer/file_descriptor.h
index c8a5b15..5e524d9 100644
--- a/payload_consumer/file_descriptor.h
+++ b/payload_consumer/file_descriptor.h
@@ -87,6 +87,11 @@
                         uint64_t length,
                         int* result) = 0;
 
+  // Flushes any cached data. The descriptor must be opened prior to this
+  // call. Returns false if it fails to write data. Implementations may set
+  // errno accrodingly.
+  virtual bool Flush() = 0;
+
   // Closes a file descriptor. The descriptor must be open prior to this call.
   // Returns true on success, false otherwise. Specific implementations may set
   // errno accordingly.
@@ -118,6 +123,7 @@
                 uint64_t start,
                 uint64_t length,
                 int* result) override;
+  bool Flush() override;
   bool Close() override;
   bool IsSettingErrno() override {
     return true;