libsnapshot: Fix crash in cow writer test due to missing ASSERT.

Bug: N/A
Test: vts_libsnapshot_test
Change-Id: I72cf6f52fc15061da669d14cf5d334b44ad83501
This commit is contained in:
David Anderson 2023-02-07 05:22:22 +00:00
parent 111bec1e90
commit bda181a86a
2 changed files with 6 additions and 7 deletions

View file

@ -298,13 +298,12 @@ bool CowWriter::Initialize(borrowed_fd fd) {
return false;
}
bool ret = OpenForWrite();
if (ret) {
InitWorkers();
if (!OpenForWrite()) {
return false;
}
return ret;
InitWorkers();
return true;
}
bool CowWriter::InitializeAppend(android::base::unique_fd&& fd, uint64_t label) {

View file

@ -33,8 +33,8 @@ TEST_F(CompressedSnapshotWriterTest, ReadAfterWrite) {
TemporaryFile cow_device_file{};
android::snapshot::CowOptions options{.block_size = BLOCK_SIZE};
android::snapshot::CompressedSnapshotWriter snapshot_writer{options};
snapshot_writer.SetCowDevice(android::base::unique_fd{cow_device_file.fd});
snapshot_writer.Initialize();
ASSERT_TRUE(snapshot_writer.SetCowDevice(android::base::unique_fd{cow_device_file.fd}));
ASSERT_TRUE(snapshot_writer.Initialize());
std::vector<unsigned char> buffer;
buffer.resize(BLOCK_SIZE);
std::fill(buffer.begin(), buffer.end(), 123);