From 91a649ab62c9cf60ae9d02dd38c23fc23f98a1f3 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 21 May 2018 16:05:56 -0700 Subject: updater: Add ABORT command. This will be used for testing purpose only, replacing the previously used "fail", to intentionally abort an update. As we're separating the logic between commands parsing and execution, "abort" needs to be considered as a valid command during the parsing. Test: recovery_unit_test and recovery_component_test on marlin. Change-Id: I47c41c423e62c41cc8515fd92f3c5959be08da02 --- updater/commands.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'updater/commands.cpp') diff --git a/updater/commands.cpp b/updater/commands.cpp index fb19ebc9a..e88149678 100644 --- a/updater/commands.cpp +++ b/updater/commands.cpp @@ -29,8 +29,16 @@ using namespace std::string_literals; +bool Command::abort_allowed_ = false; + Command::Type Command::ParseType(const std::string& type_str) { - if (type_str == "bsdiff") { + if (type_str == "abort") { + if (!abort_allowed_) { + LOG(ERROR) << "ABORT disallowed"; + return Type::LAST; + } + return Type::ABORT; + } else if (type_str == "bsdiff") { return Type::BSDIFF; } else if (type_str == "erase") { return Type::ERASE; @@ -237,6 +245,13 @@ Command Command::Parse(const std::string& line, size_t index, std::string* err) src_hash, &source_info, err)) { return {}; } + } else if (op == Type::ABORT) { + // No-op, other than sanity checking the input args. + if (pos != tokens.size()) { + *err = android::base::StringPrintf("invalid number of args: %zu (expected 0)", + tokens.size() - pos); + return {}; + } } else { *err = "invalid op"; return {}; -- cgit v1.2.3