Initialize writer before executing zucchini ops

Test: th
Bug: 202175173
Change-Id: I85f7634a6b2300d2c8fa8d0ffec2931cf65fb74e
diff --git a/payload_consumer/install_operation_executor.cc b/payload_consumer/install_operation_executor.cc
index 47c6b5c..e95130b 100644
--- a/payload_consumer/install_operation_executor.cc
+++ b/payload_consumer/install_operation_executor.cc
@@ -234,6 +234,7 @@
     const void* data,
     size_t count) {
   TEST_AND_RETURN_FALSE(source_fd != nullptr);
+  TEST_AND_RETURN_FALSE(writer->Init(operation.dst_extents(), block_size_));
   switch (operation.type()) {
     case InstallOperation::SOURCE_BSDIFF:
     case InstallOperation::BSDIFF:
@@ -266,7 +267,6 @@
       std::move(reader),
       utils::BlocksInExtents(operation.src_extents()) * block_size_);
 
-  TEST_AND_RETURN_FALSE(writer->Init(operation.dst_extents(), block_size_));
   auto dst_file = std::make_unique<BsdiffExtentFile>(
       std::move(writer),
       utils::BlocksInExtents(operation.dst_extents()) * block_size_);
@@ -291,7 +291,6 @@
       std::move(reader),
       utils::BlocksInExtents(operation.src_extents()) * block_size_));
 
-  TEST_AND_RETURN_FALSE(writer->Init(operation.dst_extents(), block_size_));
   puffin::UniqueStreamPtr dst_stream(new PuffinExtentStream(
       std::move(writer),
       utils::BlocksInExtents(operation.dst_extents()) * block_size_));
diff --git a/payload_consumer/partition_writer.cc b/payload_consumer/partition_writer.cc
index 15996d4..4625a7a 100644
--- a/payload_consumer/partition_writer.cc
+++ b/payload_consumer/partition_writer.cc
@@ -195,7 +195,6 @@
                                               size_t count) {
   // Setup the ExtentWriter stack based on the operation type.
   std::unique_ptr<ExtentWriter> writer = CreateBaseExtentWriter();
-  writer->Init(operation.dst_extents(), block_size_);
   return install_op_executor_.ExecuteReplaceOperation(
       operation, std::move(writer), data, count);
 }
@@ -222,7 +221,6 @@
     PLOG(WARNING) << "BlkIoctl failed. Falling back to write 0s for remainder "
                      "of this operation.";
     auto writer = CreateBaseExtentWriter();
-    writer->Init(operation.dst_extents(), block_size_);
     return install_op_executor_.ExecuteZeroOrDiscardOperation(
         operation, std::move(writer));
   }
@@ -253,7 +251,6 @@
   }
 
   auto writer = CreateBaseExtentWriter();
-  writer->Init(optimized.dst_extents(), block_size_);
   return install_op_executor_.ExecuteSourceCopyOperation(
       optimized, std::move(writer), source_fd);
 }
@@ -266,7 +263,6 @@
   TEST_AND_RETURN_FALSE(source_fd != nullptr);
 
   auto writer = CreateBaseExtentWriter();
-  writer->Init(operation.dst_extents(), block_size_);
   return install_op_executor_.ExecuteDiffOperation(
       operation, std::move(writer), source_fd, data, count);
 }