summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
Diffstat (limited to 'updater')
-rw-r--r--updater/blockimg.cpp7
-rw-r--r--updater/commands.cpp17
-rw-r--r--updater/include/private/commands.h12
-rw-r--r--updater/install.cpp50
4 files changed, 36 insertions, 50 deletions
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 937c5e14b..fc713859b 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -1489,6 +1489,11 @@ static int PerformCommandErase(CommandParameters& params) {
return 0;
}
+static int PerformCommandAbort(CommandParameters&) {
+ LOG(INFO) << "Aborting as instructed";
+ return -1;
+}
+
using CommandFunction = std::function<int(CommandParameters&)>;
using CommandMap = std::unordered_map<Command::Type, CommandFunction>;
@@ -1888,6 +1893,7 @@ Value* BlockImageVerifyFn(const char* name, State* state,
// Commands which are not allowed are set to nullptr to skip them completely.
const CommandMap command_map{
// clang-format off
+ { Command::Type::ABORT, PerformCommandAbort },
{ Command::Type::BSDIFF, PerformCommandDiff },
{ Command::Type::ERASE, nullptr },
{ Command::Type::FREE, PerformCommandFree },
@@ -1908,6 +1914,7 @@ Value* BlockImageUpdateFn(const char* name, State* state,
const std::vector<std::unique_ptr<Expr>>& argv) {
const CommandMap command_map{
// clang-format off
+ { Command::Type::ABORT, PerformCommandAbort },
{ Command::Type::BSDIFF, PerformCommandDiff },
{ Command::Type::ERASE, PerformCommandErase },
{ Command::Type::FREE, PerformCommandFree },
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 {};
diff --git a/updater/include/private/commands.h b/updater/include/private/commands.h
index 784892fb5..087d7cfbf 100644
--- a/updater/include/private/commands.h
+++ b/updater/include/private/commands.h
@@ -213,9 +213,13 @@ class PatchInfo {
// - Free the given stash data.
// - Meaningful args: StashInfo
//
+// abort
+// - Abort the current update. Allowed for testing code only.
+//
class Command {
public:
enum class Type {
+ ABORT,
BSDIFF,
ERASE,
FREE,
@@ -280,6 +284,11 @@ class Command {
}
private:
+ friend class ResumableUpdaterTest;
+ friend class UpdaterTest;
+
+ FRIEND_TEST(CommandsTest, Parse_ABORT_Allowed);
+ FRIEND_TEST(CommandsTest, Parse_InvalidNumberOfArgs);
FRIEND_TEST(CommandsTest, ParseTargetInfoAndSourceInfo_InvalidInput);
FRIEND_TEST(CommandsTest, ParseTargetInfoAndSourceInfo_StashesOnly);
FRIEND_TEST(CommandsTest, ParseTargetInfoAndSourceInfo_SourceBlocksAndStashes);
@@ -293,6 +302,9 @@ class Command {
const std::string& src_hash, SourceInfo* source,
std::string* err);
+ // Allows parsing ABORT command, which should be used for testing purpose only.
+ static bool abort_allowed_;
+
// The type of the command.
Type type_{ Type::LAST };
// The index of the Command object, which is specified by the caller.
diff --git a/updater/install.cpp b/updater/install.cpp
index 6f83440da..5ebdab49d 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -262,9 +262,7 @@ Value* ApplyPatchFn(const char* name, State* state,
// apply_patch_check(filename, [sha1, ...])
// Returns true if the contents of filename or the temporary copy in the cache partition (if
// present) have a SHA-1 checksum equal to one of the given sha1 values. sha1 values are
-// specified as 40 hex digits. This function differs from sha1_check(read_file(filename),
-// sha1 [, ...]) in that it knows to check the cache partition copy, so apply_patch_check() will
-// succeed even if the file was corrupted by an interrupted apply_patch() update.
+// specified as 40 hex digits.
Value* ApplyPatchCheckFn(const char* name, State* state,
const std::vector<std::unique_ptr<Expr>>& argv) {
if (argv.size() < 1) {
@@ -287,51 +285,6 @@ Value* ApplyPatchCheckFn(const char* name, State* state,
return StringValue(result == 0 ? "t" : "");
}
-// sha1_check(data)
-// to return the sha1 of the data (given in the format returned by
-// read_file).
-//
-// sha1_check(data, sha1_hex, [sha1_hex, ...])
-// returns the sha1 of the file if it matches any of the hex
-// strings passed, or "" if it does not equal any of them.
-//
-Value* Sha1CheckFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
- if (argv.size() < 1) {
- return ErrorAbort(state, kArgsParsingFailure, "%s() expects at least 1 arg", name);
- }
-
- std::vector<std::unique_ptr<Value>> args;
- if (!ReadValueArgs(state, argv, &args)) {
- return nullptr;
- }
-
- if (args[0]->type == VAL_INVALID) {
- return StringValue("");
- }
- uint8_t digest[SHA_DIGEST_LENGTH];
- SHA1(reinterpret_cast<const uint8_t*>(args[0]->data.c_str()), args[0]->data.size(), digest);
-
- if (argv.size() == 1) {
- return StringValue(print_sha1(digest));
- }
-
- for (size_t i = 1; i < argv.size(); ++i) {
- uint8_t arg_digest[SHA_DIGEST_LENGTH];
- if (args[i]->type != VAL_STRING) {
- LOG(ERROR) << name << "(): arg " << i << " is not a string; skipping";
- } else if (ParseSha1(args[i]->data, arg_digest) != 0) {
- // Warn about bad args and skip them.
- LOG(ERROR) << name << "(): error parsing \"" << args[i]->data << "\" as sha-1; skipping";
- } else if (memcmp(digest, arg_digest, SHA_DIGEST_LENGTH) == 0) {
- // Found a match.
- return args[i].release();
- }
- }
-
- // Didn't match any of the hex strings; return false.
- return StringValue("");
-}
-
// mount(fs_type, partition_type, location, mount_point)
// mount(fs_type, partition_type, location, mount_point, mount_options)
@@ -1025,7 +978,6 @@ void RegisterInstallFunctions() {
RegisterFunction("wipe_block_device", WipeBlockDeviceFn);
RegisterFunction("read_file", ReadFileFn);
- RegisterFunction("sha1_check", Sha1CheckFn);
RegisterFunction("write_value", WriteValueFn);
RegisterFunction("wipe_cache", WipeCacheFn);