Make InstallOpExecutor take in unique_ptr
Test: th
Change-Id: Ic815eeff654d2943ac6339ae7c991e9e65fad87e
diff --git a/payload_consumer/install_operation_executor.cc b/payload_consumer/install_operation_executor.cc
index fa176da..eb4efe6 100644
--- a/payload_consumer/install_operation_executor.cc
+++ b/payload_consumer/install_operation_executor.cc
@@ -191,7 +191,7 @@
}
bool InstallOperationExecutor::ExecuteZeroOrDiscardOperation(
- const InstallOperation& operation, ExtentWriter* writer) {
+ const InstallOperation& operation, std::unique_ptr<ExtentWriter> writer) {
TEST_AND_RETURN_FALSE(operation.type() == InstallOperation::ZERO ||
operation.type() == InstallOperation::DISCARD);
using base::MemoryMappedFile;
@@ -216,12 +216,12 @@
bool InstallOperationExecutor::ExecuteSourceCopyOperation(
const InstallOperation& operation,
- ExtentWriter* writer,
+ std::unique_ptr<ExtentWriter> writer,
FileDescriptorPtr source_fd) {
TEST_AND_RETURN_FALSE(operation.type() == InstallOperation::SOURCE_COPY);
TEST_AND_RETURN_FALSE(writer->Init(operation.dst_extents(), block_size_));
return fd_utils::CommonHashExtents(
- source_fd, operation.src_extents(), writer, block_size_, nullptr);
+ source_fd, operation.src_extents(), writer.get(), block_size_, nullptr);
}
bool InstallOperationExecutor::ExecuteDiffOperation(
diff --git a/payload_consumer/install_operation_executor.h b/payload_consumer/install_operation_executor.h
index b064cc8..f64318a 100644
--- a/payload_consumer/install_operation_executor.h
+++ b/payload_consumer/install_operation_executor.h
@@ -35,9 +35,9 @@
const void* data,
size_t count);
bool ExecuteZeroOrDiscardOperation(const InstallOperation& operation,
- ExtentWriter* writer);
+ std::unique_ptr<ExtentWriter> writer);
bool ExecuteSourceCopyOperation(const InstallOperation& operation,
- ExtentWriter* writer,
+ std::unique_ptr<ExtentWriter> writer,
FileDescriptorPtr source_fd);
bool ExecuteDiffOperation(const InstallOperation& operation,
diff --git a/payload_consumer/install_operation_executor_unittest.cc b/payload_consumer/install_operation_executor_unittest.cc
index 3c2fb0f..e4135fc 100644
--- a/payload_consumer/install_operation_executor_unittest.cc
+++ b/payload_consumer/install_operation_executor_unittest.cc
@@ -151,7 +151,7 @@
*op.mutable_dst_extents()->Add() = ExtentForRange(2, 2);
*op.mutable_dst_extents()->Add() = ExtentForRange(6, 2);
auto writer = std::make_unique<DirectExtentWriter>(target_fd_);
- ASSERT_TRUE(executor_.ExecuteZeroOrDiscardOperation(op, writer.get()));
+ ASSERT_TRUE(executor_.ExecuteZeroOrDiscardOperation(op, std::move(writer)));
brillo::Blob actual_data;
utils::ReadExtents(
target_.path(),
@@ -177,7 +177,7 @@
auto writer = std::make_unique<DirectExtentWriter>(target_fd_);
ASSERT_TRUE(
- executor_.ExecuteSourceCopyOperation(op, writer.get(), source_fd_));
+ executor_.ExecuteSourceCopyOperation(op, std::move(writer), source_fd_));
brillo::Blob actual_data;
utils::ReadExtents(
target_.path(),
diff --git a/payload_consumer/partition_writer.cc b/payload_consumer/partition_writer.cc
index 75d738e..15996d4 100644
--- a/payload_consumer/partition_writer.cc
+++ b/payload_consumer/partition_writer.cc
@@ -223,8 +223,8 @@
"of this operation.";
auto writer = CreateBaseExtentWriter();
writer->Init(operation.dst_extents(), block_size_);
- return install_op_executor_.ExecuteZeroOrDiscardOperation(operation,
- writer.get());
+ return install_op_executor_.ExecuteZeroOrDiscardOperation(
+ operation, std::move(writer));
}
return true;
}
@@ -255,7 +255,7 @@
auto writer = CreateBaseExtentWriter();
writer->Init(optimized.dst_extents(), block_size_);
return install_op_executor_.ExecuteSourceCopyOperation(
- optimized, writer.get(), source_fd);
+ optimized, std::move(writer), source_fd);
}
bool PartitionWriter::PerformDiffOperation(const InstallOperation& operation,