Handle resume of VABC updates by emitting labels

To support resuming an update with Virtual AB Compression, we emit
labels in between operations. After writing all SOURCE_COPY, we
emit label 0. Each time we finished writing an InstallOp, we emit
a label incremented by 1. When resuming, we pass the label to CowWriter.

Test: treehugger
     1. update_device.py ota.zip
     --extra-headers="SWITCH_SLOT_ON_REBOOT=0"
     2. update_device.py ota.zip
     3. Verify that 2 did not re-start the entire update,
        only fs verification and postinstall may re-run.
Change-Id: I785cd04a35457181621ed7b8c0be9a46b6004b7b
diff --git a/payload_consumer/partition_writer.cc b/payload_consumer/partition_writer.cc
index bec2594..6f06dd2 100644
--- a/payload_consumer/partition_writer.cc
+++ b/payload_consumer/partition_writer.cc
@@ -274,7 +274,8 @@
 }
 
 bool PartitionWriter::Init(const InstallPlan* install_plan,
-                           bool source_may_exist) {
+                           bool source_may_exist,
+                           size_t next_op_index) {
   const PartitionUpdate& partition = partition_update_;
   uint32_t source_slot = install_plan->source_slot;
   uint32_t target_slot = install_plan->target_slot;
@@ -329,7 +330,7 @@
       writer->Init(target_fd_, operation.dst_extents(), block_size_));
   TEST_AND_RETURN_FALSE(writer->Write(data, operation.data_length()));
 
-  return Flush();
+  return true;
 }
 
 bool PartitionWriter::PerformZeroOrDiscardOperation(
@@ -362,7 +363,7 @@
           target_fd_, zeros.data(), chunk_length, start + offset));
     }
   }
-  return Flush();
+  return true;
 }
 
 bool PartitionWriter::PerformSourceCopyOperation(
@@ -473,7 +474,7 @@
                                                        block_size_,
                                                        nullptr));
   }
-  return Flush();
+  return true;
 }
 
 bool PartitionWriter::PerformSourceBsdiffOperation(
@@ -502,7 +503,7 @@
                                         std::move(dst_file),
                                         reinterpret_cast<const uint8_t*>(data),
                                         count) == 0);
-  return Flush();
+  return true;
 }
 
 bool PartitionWriter::PerformPuffDiffOperation(
@@ -534,7 +535,7 @@
                         reinterpret_cast<const uint8_t*>(data),
                         count,
                         kMaxCacheSize));
-  return Flush();
+  return true;
 }
 
 FileDescriptorPtr PartitionWriter::ChooseSourceFD(
@@ -652,12 +653,12 @@
   return -err;
 }
 
-std::unique_ptr<ExtentWriter> PartitionWriter::CreateBaseExtentWriter() {
-  return std::make_unique<DirectExtentWriter>();
+void PartitionWriter::CheckpointUpdateProgress(size_t next_op_index) {
+  target_fd_->Flush();
 }
 
-bool PartitionWriter::Flush() {
-  return target_fd_->Flush();
+std::unique_ptr<ExtentWriter> PartitionWriter::CreateBaseExtentWriter() {
+  return std::make_unique<DirectExtentWriter>();
 }
 
 }  // namespace chromeos_update_engine