Refactor for ISnapshotWriter removal.
Bug: 280529365
Test: update_engine_unittests
apply ota
Change-Id: I03e899ba31077f828268be3775ebceba3850c528
diff --git a/aosp/dynamic_partition_control_android.cc b/aosp/dynamic_partition_control_android.cc
index 19ea6ec..a309b6e 100644
--- a/aosp/dynamic_partition_control_android.cc
+++ b/aosp/dynamic_partition_control_android.cc
@@ -1424,11 +1424,11 @@
return metadata_device_ != nullptr;
}
-std::unique_ptr<android::snapshot::ISnapshotWriter>
+std::unique_ptr<android::snapshot::ICowWriter>
DynamicPartitionControlAndroid::OpenCowWriter(
const std::string& partition_name,
const std::optional<std::string>& source_path,
- bool) {
+ std::optional<uint64_t> label) {
auto suffix = SlotSuffixForSlotNumber(target_slot_);
auto super_device = GetSuperDevice();
@@ -1443,29 +1443,26 @@
.timeout_ms = kMapSnapshotTimeout};
// TODO(zhangkelvin) Open an APPEND mode CowWriter once there's an API to do
// it.
- return snapshot_->OpenSnapshotWriter(params, std::move(source_path));
+ return snapshot_->OpenSnapshotWriter(params, label);
} // namespace chromeos_update_engine
std::unique_ptr<FileDescriptor> DynamicPartitionControlAndroid::OpenCowFd(
const std::string& unsuffixed_partition_name,
const std::optional<std::string>& source_path,
bool is_append) {
- auto cow_writer =
- OpenCowWriter(unsuffixed_partition_name, source_path, is_append);
+ auto cow_writer = OpenCowWriter(
+ unsuffixed_partition_name, source_path, {kEndOfInstallLabel});
if (cow_writer == nullptr) {
+ LOG(ERROR) << "OpenCowWriter failed";
return nullptr;
}
- if (!cow_writer->InitializeAppend(kEndOfInstallLabel)) {
- LOG(ERROR) << "Failed to InitializeAppend(" << kEndOfInstallLabel << ")";
+ auto fd = cow_writer->OpenFileDescriptor(source_path);
+ if (fd == nullptr) {
+ LOG(ERROR) << "ICowReader::OpenFileDescriptor failed";
return nullptr;
}
- auto reader = cow_writer->OpenReader();
- if (reader == nullptr) {
- LOG(ERROR) << "ICowWriter::OpenReader() failed.";
- return nullptr;
- }
- return std::make_unique<CowWriterFileDescriptor>(std::move(cow_writer),
- std::move(reader));
+ return std::make_unique<CowWriterFileDescriptor>(
+ std::move(cow_writer), std::move(fd), source_path);
}
std::optional<base::FilePath> DynamicPartitionControlAndroid::GetSuperDevice() {
diff --git a/aosp/dynamic_partition_control_android.h b/aosp/dynamic_partition_control_android.h
index 9851a99..830901b 100644
--- a/aosp/dynamic_partition_control_android.h
+++ b/aosp/dynamic_partition_control_android.h
@@ -17,16 +17,16 @@
#ifndef UPDATE_ENGINE_AOSP_DYNAMIC_PARTITION_CONTROL_ANDROID_H_
#define UPDATE_ENGINE_AOSP_DYNAMIC_PARTITION_CONTROL_ANDROID_H_
+#include <array>
#include <memory>
#include <set>
#include <string>
#include <string_view>
-#include <array>
+#include <vector>
#include <base/files/file_util.h>
#include <libsnapshot/auto_device.h>
#include <libsnapshot/snapshot.h>
-#include <libsnapshot/snapshot_writer.h>
#include "update_engine/common/dynamic_partition_control_interface.h"
@@ -102,14 +102,14 @@
// Partition name is expected to be unsuffixed. e.g. system, vendor
// Return an interface to write to a snapshoted partition.
- std::unique_ptr<android::snapshot::ISnapshotWriter> OpenCowWriter(
+ std::unique_ptr<android::snapshot::ICowWriter> OpenCowWriter(
const std::string& unsuffixed_partition_name,
const std::optional<std::string>& source_path,
- bool is_append) override;
+ std::optional<uint64_t> label) override;
std::unique_ptr<FileDescriptor> OpenCowFd(
const std::string& unsuffixed_partition_name,
const std::optional<std::string>&,
- bool is_append = false) override;
+ bool is_append) override;
bool MapAllPartitions() override;
bool UnmapAllPartitions() override;
diff --git a/aosp/mock_dynamic_partition_control_android.h b/aosp/mock_dynamic_partition_control_android.h
index e940e50..cc6ebf3 100644
--- a/aosp/mock_dynamic_partition_control_android.h
+++ b/aosp/mock_dynamic_partition_control_android.h
@@ -17,13 +17,13 @@
#include <stdint.h>
#include <memory>
+#include <optional>
#include <set>
#include <string>
#include <gmock/gmock.h>
#include <libsnapshot/cow_writer.h>
-#include <libsnapshot/snapshot_writer.h>
#include "payload_consumer/file_descriptor.h"
#include "update_engine/aosp/dynamic_partition_control_android.h"
@@ -96,11 +96,11 @@
PrepareDynamicPartitionsForUpdate,
(uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
(override));
- MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>,
+ MOCK_METHOD(std::unique_ptr<android::snapshot::ICowWriter>,
OpenCowWriter,
(const std::string& unsuffixed_partition_name,
const std::optional<std::string>& source_path,
- bool is_append),
+ std::optional<uint64_t> label),
(override));
MOCK_METHOD(std::unique_ptr<FileDescriptor>,
OpenCowFd,