summaryrefslogtreecommitdiffstats
path: root/applypatch/applypatch_modes.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-08-31 23:24:31 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-08-31 23:24:31 +0200
commitaf522672a2e423b8c1db6db7960c62a378a40008 (patch)
tree048e988c79cb22a71dae3e951f41457d8f24f62f /applypatch/applypatch_modes.cpp
parentMerge "Enable c++17 in recovery_defaults." (diff)
parentapplypatch: Refactor applypatch(). (diff)
downloadandroid_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar.gz
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar.bz2
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar.lz
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar.xz
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.tar.zst
android_bootable_recovery-af522672a2e423b8c1db6db7960c62a378a40008.zip
Diffstat (limited to 'applypatch/applypatch_modes.cpp')
-rw-r--r--applypatch/applypatch_modes.cpp57
1 files changed, 24 insertions, 33 deletions
diff --git a/applypatch/applypatch_modes.cpp b/applypatch/applypatch_modes.cpp
index f130ea222..b46659808 100644
--- a/applypatch/applypatch_modes.cpp
+++ b/applypatch/applypatch_modes.cpp
@@ -35,56 +35,48 @@
#include "applypatch/applypatch.h"
#include "edify/expr.h"
-static int CheckMode(const std::string& target) {
- return applypatch_check(target, {});
+static int CheckMode(const std::string& target_emmc) {
+ std::string err;
+ auto target = Partition::Parse(target_emmc, &err);
+ if (!target) {
+ LOG(ERROR) << "Failed to parse target \"" << target_emmc << "\": " << err;
+ return 2;
+ }
+ return CheckPartition(target) ? 0 : 1;
}
static int FlashMode(const std::string& target_emmc, const std::string& source_file) {
- std::vector<std::string> pieces = android::base::Split(target_emmc, ":");
- if (pieces.size() != 4 || pieces[0] != "EMMC") {
+ std::string err;
+ auto target = Partition::Parse(target_emmc, &err);
+ if (!target) {
+ LOG(ERROR) << "Failed to parse target \"" << target_emmc << "\": " << err;
return 2;
}
- size_t target_size;
- if (!android::base::ParseUint(pieces[2], &target_size) || target_size == 0) {
- LOG(ERROR) << "Failed to parse \"" << pieces[2] << "\" as byte count";
- return 1;
- }
- return applypatch_flash(source_file.c_str(), target_emmc.c_str(), pieces[3].c_str(), target_size);
+ return FlashPartition(target, source_file) ? 0 : 1;
}
static int PatchMode(const std::string& target_emmc, const std::string& source_emmc,
const std::string& patch_file, const std::string& bonus_file) {
- std::vector<std::string> target_pieces = android::base::Split(target_emmc, ":");
- if (target_pieces.size() != 4 || target_pieces[0] != "EMMC") {
+ std::string err;
+ auto target = Partition::Parse(target_emmc, &err);
+ if (!target) {
+ LOG(ERROR) << "Failed to parse target \"" << target_emmc << "\": " << err;
return 2;
}
- size_t target_size;
- if (!android::base::ParseUint(target_pieces[2], &target_size) || target_size == 0) {
- LOG(ERROR) << "Failed to parse \"" << target_pieces[2] << "\" as byte count";
- return 1;
- }
-
- std::vector<std::string> source_pieces = android::base::Split(source_emmc, ":");
- if (source_pieces.size() != 4 || source_pieces[0] != "EMMC") {
+ auto source = Partition::Parse(source_emmc, &err);
+ if (!source) {
+ LOG(ERROR) << "Failed to parse source \"" << source_emmc << "\": " << err;
return 2;
}
- size_t source_size;
- if (!android::base::ParseUint(source_pieces[2], &source_size) || source_size == 0) {
- LOG(ERROR) << "Failed to parse \"" << source_pieces[2] << "\" as byte count";
- return 1;
- }
-
- std::string contents;
- if (!android::base::ReadFileToString(patch_file, &contents)) {
+ std::string patch_contents;
+ if (!android::base::ReadFileToString(patch_file, &patch_contents)) {
PLOG(ERROR) << "Failed to read patch file \"" << patch_file << "\"";
return 1;
}
- std::vector<std::unique_ptr<Value>> patches;
- patches.push_back(std::make_unique<Value>(Value::Type::BLOB, std::move(contents)));
- std::vector<std::string> sha1s{ source_pieces[3] };
+ Value patch(Value::Type::BLOB, std::move(patch_contents));
std::unique_ptr<Value> bonus;
if (!bonus_file.empty()) {
std::string bonus_contents;
@@ -95,8 +87,7 @@ static int PatchMode(const std::string& target_emmc, const std::string& source_e
bonus = std::make_unique<Value>(Value::Type::BLOB, std::move(bonus_contents));
}
- return applypatch(source_emmc.c_str(), target_emmc.c_str(), target_pieces[3].c_str(), target_size,
- sha1s, patches, bonus.get());
+ return PatchPartition(target, source, patch, bonus.get()) ? 0 : 1;
}
static void Usage() {