Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8542f3e4 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Remove ISnapshotWriter."

parents 7f72b30e 5eae2cb4
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -85,11 +85,9 @@ filegroup {
        "android/snapshot/snapshot.proto",
        "device_info.cpp",
        "snapshot.cpp",
        "snapshot_reader.cpp",
        "snapshot_stats.cpp",
        "snapshot_stub.cpp",
        "snapshot_metadata_updater.cpp",
        "snapshot_writer.cpp",
        "partition_cow_creator.cpp",
        "return.cpp",
        "utility.cpp",
@@ -165,6 +163,9 @@ cc_defaults {
        "liblz4",
        "libzstd",
    ],
    header_libs: [
        "libupdate_engine_headers",
    ],
    export_include_dirs: ["include"],
}

@@ -179,6 +180,7 @@ cc_library_static {
        "libsnapshot_cow/cow_format.cpp",
        "libsnapshot_cow/cow_reader.cpp",
        "libsnapshot_cow/parser_v2.cpp",
        "libsnapshot_cow/snapshot_reader.cpp",
        "libsnapshot_cow/writer_base.cpp",
        "libsnapshot_cow/writer_v2.cpp",
    ],
@@ -224,9 +226,7 @@ cc_defaults {
    srcs: [
        "partition_cow_creator_test.cpp",
        "snapshot_metadata_updater_test.cpp",
        "snapshot_reader_test.cpp",
        "snapshot_test.cpp",
        "snapshot_writer_test.cpp",
    ],
    shared_libs: [
        "libbinder",
@@ -372,6 +372,7 @@ cc_test {
        "libsnapshot_cow_defaults",
    ],
    srcs: [
        "libsnapshot_cow/snapshot_reader_test.cpp",
        "libsnapshot_cow/test_v2.cpp",
    ],
    cflags: [
+7 −2
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@
#include <android-base/unique_fd.h>
#include <libsnapshot/cow_format.h>

namespace chromeos_update_engine {
class FileDescriptor;
}  // namespace chromeos_update_engine

namespace android {
namespace snapshot {

@@ -32,6 +36,8 @@ class ICowOpIter;
// Interface for reading from a snapuserd COW.
class ICowReader {
  public:
    using FileDescriptor = chromeos_update_engine::FileDescriptor;

    virtual ~ICowReader() {}

    // Return the file header.
@@ -109,10 +115,9 @@ class CowReader final : public ICowReader {
    bool Parse(android::base::borrowed_fd fd, std::optional<uint64_t> label = {});

    bool InitForMerge(android::base::unique_fd&& fd);
    bool VerifyMergeOps() override;

    bool VerifyMergeOps() override;
    bool GetFooter(CowFooter* footer) override;

    bool GetLastLabel(uint64_t* label) override;

    // Create a CowOpIter object which contains footer_.num_ops
+13 −0
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ struct CowOptions {
// will occur in the sequence they were added to the COW.
class ICowWriter {
  public:
    using FileDescriptor = chromeos_update_engine::FileDescriptor;

    virtual ~ICowWriter() {}

    // Encode an operation that copies the contents of |old_block| to the
@@ -93,6 +95,17 @@ class ICowWriter {

    virtual uint32_t GetBlockSize() const = 0;
    virtual std::optional<uint32_t> GetMaxBlocks() const = 0;

    // Open an ICowReader for this writer. The reader will be a snapshot of the
    // current operations in the writer; new writes after OpenReader() will not
    // be reflected.
    virtual std::unique_ptr<ICowReader> OpenReader() = 0;

    // Open a file descriptor. This allows reading and seeing through the cow
    // as if it were a normal file. The optional source_device must be a valid
    // path if the CowReader contains any copy or xor operations.
    virtual std::unique_ptr<FileDescriptor> OpenFileDescriptor(
            const std::optional<std::string>& source_device) = 0;
};

class CompressWorker {
+8 −8
Original line number Diff line number Diff line
@@ -15,17 +15,16 @@
//

#include <gmock/gmock.h>
#include <libsnapshot/snapshot_writer.h>
#include <libsnapshot/cow_writer.h>

namespace android::snapshot {

class MockSnapshotWriter : public ISnapshotWriter {
class MockCowWriter : public ICowWriter {
  public:
    using FileDescriptor = ISnapshotWriter::FileDescriptor;
    using FileDescriptor = chromeos_update_engine::FileDescriptor;

    MOCK_METHOD(bool, Finalize, (), (override));

    // Return number of bytes the cow image occupies on disk.
    MOCK_METHOD(uint64_t, GetCowSize, (), (override));

    MOCK_METHOD(bool, AddCopy, (uint64_t, uint64_t, uint64_t), (override));
@@ -35,11 +34,12 @@ class MockSnapshotWriter : public ISnapshotWriter {
    MOCK_METHOD(bool, AddZeroBlocks, (uint64_t, uint64_t), (override));
    MOCK_METHOD(bool, AddLabel, (uint64_t), (override));
    MOCK_METHOD(bool, AddSequenceData, (size_t, const uint32_t*), (override));
    MOCK_METHOD(bool, Initialize, (), (override));
    MOCK_METHOD(bool, InitializeAppend, (uint64_t), (override));
    MOCK_METHOD(bool, VerifyMergeOps, (), (override, const, noexcept));
    MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenReader, (), (override));
    MOCK_METHOD(uint32_t, GetBlockSize, (), (override, const));
    MOCK_METHOD(std::optional<uint32_t>, GetMaxBlocks, (), (override, const));

    MOCK_METHOD(std::unique_ptr<ICowReader>, OpenReader, (), (override));
    MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenFileDescriptor,
                (const std::optional<std::string>&), (override));
};

}  // namespace android::snapshot
+2 −2
Original line number Diff line number Diff line
@@ -42,9 +42,9 @@ class MockSnapshotManager : public ISnapshotManager {
                (const android::fs_mgr::CreateLogicalPartitionParams& params,
                 std::string* snapshot_path),
                (override));
    MOCK_METHOD(std::unique_ptr<ISnapshotWriter>, OpenSnapshotWriter,
    MOCK_METHOD(std::unique_ptr<ICowWriter>, OpenSnapshotWriter,
                (const android::fs_mgr::CreateLogicalPartitionParams& params,
                 const std::optional<std::string>&),
                 std::optional<uint64_t>),
                (override));
    MOCK_METHOD(bool, UnmapUpdateSnapshot, (const std::string& target_partition_name), (override));
    MOCK_METHOD(bool, NeedSnapshotsInFirstStageMount, (), (override));
Loading