Use bspatch as a library.
Test: mma
Bug: 26982501
Change-Id: Iafb6a2a4e6cb747004fbf1980e7f0b29108eb54f
diff --git a/Android.mk b/Android.mk
index 34a9a5c..f6064df 100644
--- a/Android.mk
+++ b/Android.mk
@@ -500,7 +500,6 @@
LOCAL_MODULE := update_engine
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_REQUIRED_MODULES := \
- bspatch \
cacerts_google
ifeq ($(local_use_weave),1)
LOCAL_REQUIRED_MODULES += updater.json
@@ -547,8 +546,6 @@
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_REQUIRED_MODULES := \
- bspatch_recovery
LOCAL_CPP_EXTENSION := .cc
LOCAL_CLANG := true
LOCAL_CFLAGS := \
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 507ad8c..1e96c9e 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -34,6 +34,7 @@
#include <base/strings/stringprintf.h>
#include <brillo/data_encoding.h>
#include <brillo/make_unique_ptr.h>
+#include <bspatch.h>
#include <google/protobuf/repeated_field.h>
#include "update_engine/common/constants.h"
@@ -1183,31 +1184,14 @@
operation.dst_length(),
&output_positions));
- string temp_filename;
- TEST_AND_RETURN_FALSE(utils::MakeTempFile("au_patch.XXXXXX",
- &temp_filename,
- nullptr));
- ScopedPathUnlinker path_unlinker(temp_filename);
- {
- int fd = open(temp_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
- ScopedFdCloser fd_closer(&fd);
- TEST_AND_RETURN_FALSE(
- utils::WriteAll(fd, buffer_.data(), operation.data_length()));
- }
-
- // Update the buffer to release the patch data memory as soon as the patch
- // file is written out.
+ TEST_AND_RETURN_FALSE(bsdiff::bspatch(target_path_.c_str(),
+ target_path_.c_str(),
+ buffer_.data(),
+ buffer_.size(),
+ input_positions.c_str(),
+ output_positions.c_str()) == 0);
DiscardBuffer(true, buffer_.size());
- vector<string> cmd{kBspatchPath, target_path_, target_path_, temp_filename,
- input_positions, output_positions};
-
- int return_code = 0;
- TEST_AND_RETURN_FALSE(
- Subprocess::SynchronousExecFlags(cmd, Subprocess::kSearchPath,
- &return_code, nullptr));
- TEST_AND_RETURN_FALSE(return_code == 0);
-
if (operation.dst_length() % block_size_) {
// Zero out rest of final block.
// TODO(adlr): build this into bspatch; it's more efficient that way.
@@ -1269,30 +1253,13 @@
operation.dst_length(),
&output_positions));
- string temp_filename;
- TEST_AND_RETURN_FALSE(utils::MakeTempFile("au_patch.XXXXXX",
- &temp_filename,
- nullptr));
- ScopedPathUnlinker path_unlinker(temp_filename);
- {
- int fd = open(temp_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
- ScopedFdCloser fd_closer(&fd);
- TEST_AND_RETURN_FALSE(
- utils::WriteAll(fd, buffer_.data(), operation.data_length()));
- }
-
- // Update the buffer to release the patch data memory as soon as the patch
- // file is written out.
+ TEST_AND_RETURN_FALSE(bsdiff::bspatch(source_path_.c_str(),
+ target_path_.c_str(),
+ buffer_.data(),
+ buffer_.size(),
+ input_positions.c_str(),
+ output_positions.c_str()) == 0);
DiscardBuffer(true, buffer_.size());
-
- vector<string> cmd{kBspatchPath, source_path_, target_path_, temp_filename,
- input_positions, output_positions};
-
- int return_code = 0;
- TEST_AND_RETURN_FALSE(
- Subprocess::SynchronousExecFlags(cmd, Subprocess::kSearchPath,
- &return_code, nullptr));
- TEST_AND_RETURN_FALSE(return_code == 0);
return true;
}
diff --git a/payload_consumer/payload_constants.cc b/payload_consumer/payload_constants.cc
index 60b857e..de0fd74 100644
--- a/payload_consumer/payload_constants.cc
+++ b/payload_consumer/payload_constants.cc
@@ -31,7 +31,6 @@
const char kLegacyPartitionNameRoot[] = "system";
const char kDeltaMagic[4] = {'C', 'r', 'A', 'U'};
-const char kBspatchPath[] = "bspatch";
// The zlib in Android and Chrome OS are currently compatible with each other,
// so they are sharing the same array, but if in the future they are no longer