Enable brotli_bsdiff in update package generation am: de1685fd76
am: 8679c142bb
Change-Id: I41c20b1dbcd6691baee6d4577b6e1ea3b977ec57
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index bcbc3a5..877e13f 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -40,6 +40,7 @@
#include <base/threading/simple_thread.h>
#include <brillo/data_encoding.h>
#include <bsdiff/bsdiff.h>
+#include <bsdiff/patch_writer_factory.h>
#include "update_engine/common/hash_calculator.h"
#include "update_engine/common/subprocess.h"
@@ -73,6 +74,8 @@
// memory intensive, so we limit these operations to 150 MiB.
const uint64_t kMaxPuffdiffDestinationSize = 150 * 1024 * 1024; // bytes
+const int kBrotliCompressionQuality = 11;
+
// Process a range of blocks from |range_start| to |range_end| in the extent at
// position |*idx_p| of |extents|. If |do_remove| is true, this range will be
// removed, which may cause the extent to be trimmed, split or removed entirely.
@@ -740,21 +743,33 @@
TEST_AND_RETURN_FALSE(base::CreateTemporaryFile(&patch));
ScopedPathUnlinker unlinker(patch.value());
+ std::unique_ptr<bsdiff::PatchWriterInterface> bsdiff_patch_writer;
+ InstallOperation_Type operation_type = InstallOperation::BSDIFF;
+ if (version.OperationAllowed(InstallOperation::BROTLI_BSDIFF)) {
+ bsdiff_patch_writer =
+ bsdiff::CreateBSDF2PatchWriter(patch.value(),
+ bsdiff::CompressorType::kBrotli,
+ kBrotliCompressionQuality);
+ operation_type = InstallOperation::BROTLI_BSDIFF;
+ } else {
+ bsdiff_patch_writer = bsdiff::CreateBsdiffPatchWriter(patch.value());
+ if (version.OperationAllowed(InstallOperation::SOURCE_BSDIFF)) {
+ operation_type = InstallOperation::SOURCE_BSDIFF;
+ }
+ }
+
brillo::Blob bsdiff_delta;
TEST_AND_RETURN_FALSE(0 == bsdiff::bsdiff(old_data.data(),
old_data.size(),
new_data.data(),
new_data.size(),
- patch.value().c_str(),
+ bsdiff_patch_writer.get(),
nullptr));
TEST_AND_RETURN_FALSE(utils::ReadFile(patch.value(), &bsdiff_delta));
CHECK_GT(bsdiff_delta.size(), static_cast<brillo::Blob::size_type>(0));
if (bsdiff_delta.size() < data_blob.size()) {
- operation.set_type(
- version.OperationAllowed(InstallOperation::SOURCE_BSDIFF)
- ? InstallOperation::SOURCE_BSDIFF
- : InstallOperation::BSDIFF);
+ operation.set_type(operation_type);
data_blob = std::move(bsdiff_delta);
}
}