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

Commit b4a81ccd authored by Daniel Rosenberg's avatar Daniel Rosenberg
Browse files

reland: Rename Flush to Finalize

As we change to a more resumable format, flush mostly writes the final
parts of the file that are needed, which would write extra data that is
not needed to continue writing, and would immediately be overwritten.

Additionally, in the next patch we will fsync the file after adding an
op, making the flush built in, and the Finalize name more appropriate.

Bug: 168829493
Test: builds
Change-Id: Iccc6580ac72ff066cfeeb32e3cdaf69c5ba615fc
parent ba8a3097
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ TEST_F(CowTest, ReadWrite) {
    ASSERT_TRUE(writer.AddCopy(10, 20));
    ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer.AddZeroBlocks(51, 2));
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

@@ -145,7 +145,7 @@ TEST_F(CowTest, CompressGz) {
    data.resize(options.block_size, '\0');

    ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

@@ -182,7 +182,7 @@ TEST_F(CowTest, CompressTwoBlocks) {
    data.resize(options.block_size * 2, '\0');

    ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

@@ -224,7 +224,7 @@ TEST_P(CompressionTest, HorribleSink) {
    data.resize(options.block_size, '\0');

    ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

@@ -259,7 +259,7 @@ TEST_F(CowTest, GetSize) {
    ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer.AddZeroBlocks(51, 2));
    auto size_before = writer.GetCowSize();
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());
    auto size_after = writer.GetCowSize();
    ASSERT_EQ(size_before, size_after);
    struct stat buf;
@@ -279,7 +279,7 @@ TEST_F(CowTest, Append) {
    std::string data = "This is some data, believe it";
    data.resize(options.block_size, '\0');
    ASSERT_TRUE(writer->AddRawBlocks(50, data.data(), data.size()));
    ASSERT_TRUE(writer->Flush());
    ASSERT_TRUE(writer->Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

@@ -289,7 +289,7 @@ TEST_F(CowTest, Append) {
    std::string data2 = "More data!";
    data2.resize(options.block_size, '\0');
    ASSERT_TRUE(writer->AddRawBlocks(51, data2.data(), data2.size()));
    ASSERT_TRUE(writer->Flush());
    ASSERT_TRUE(writer->Finalize());

    ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);

+1 −1
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ void SnapuserdTest::CreateCowDevice(std::unique_ptr<TemporaryFile>& cow) {
    ASSERT_TRUE(writer.AddRawBlocks(blk_random2_replace_start, random_buffer_2_.get(), size_));

    // Flush operations
    ASSERT_TRUE(writer.Flush());
    ASSERT_TRUE(writer.Finalize());

    ASSERT_EQ(lseek(cow->fd, 0, SEEK_SET), 0);
}
+1 −1
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ static void SHA256(const void*, size_t, uint8_t[]) {
#endif
}

bool CowWriter::Flush() {
bool CowWriter::Finalize() {
    header_.ops_size = ops_.size();

    memset(header_.ops_checksum, 0, sizeof(uint8_t) * 32);
+1 −1
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ bool NonAbEstimator::AnalyzePartition(const std::string& partition_name) {
        }
    }

    if (!writer->Flush()) {
    if (!writer->Finalize()) {
        return false;
    }

+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class ICowWriter {

    // Flush all pending writes. This must be called before closing the writer
    // to ensure that the correct headers and footers are written.
    virtual bool Flush() = 0;
    virtual bool Finalize() = 0;

    // Return number of bytes the cow image occupies on disk.
    virtual uint64_t GetCowSize() = 0;
@@ -84,7 +84,7 @@ class CowWriter : public ICowWriter {
    bool Initialize(android::base::unique_fd&& fd, OpenMode mode = OpenMode::WRITE);
    bool Initialize(android::base::borrowed_fd fd, OpenMode mode = OpenMode::WRITE);

    bool Flush() override;
    bool Finalize() override;

    uint64_t GetCowSize() override;

Loading