diff options
author | Tom Cherry <tomcherry@google.com> | 2018-09-05 15:11:44 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2018-09-21 12:50:39 -0700 |
commit | 4aa60b382cf758ac366045b7d2efd3b2f68bd659 (patch) | |
tree | 74dd8d39c97c5f392eb32cdad56cb1de7019f111 /fastboot/engine.cpp | |
parent | dfd85df11ace52e8b7076591e3e31dc087467f01 (diff) |
fastboot: clean up CheckRequirements
CheckRequirements() had various issues that are cleaned up here,
1) Move from C string parsing to C++
2) Moved from C data structures to C++, including fixing memory leaks.
3) Removed the 'cur_product' global and the 'query_save' function that
stores it
4) Actually writing tests for the parsing function for
android-info.txt
5) Check that a variable needs to be checked for a given product before
trying to read it. Previously, fastboot would fail if a variable
isn't recognized on a device, even if the check should be ignored.
A lot of flexibility is allowed for the input strings, to keep
backwards compatibility with the previous parsers.
Test: fastboot works, unit tests
Change-Id: Idc3bba8b8fe829d8eefe5f6c495e63a9441c0b60
Diffstat (limited to 'fastboot/engine.cpp')
-rw-r--r-- | fastboot/engine.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp index d80bc0624..a43e7a6bb 100644 --- a/fastboot/engine.cpp +++ b/fastboot/engine.cpp @@ -136,69 +136,6 @@ void fb_resize_partition(const std::string& partition, const std::string& size) RUN_COMMAND(fb->RawCommand(FB_CMD_RESIZE_PARTITION ":" + partition + ":" + size)); } -static int match(const char* str, const char** value, unsigned count) { - unsigned n; - - for (n = 0; n < count; n++) { - const char *val = value[n]; - int len = strlen(val); - int match; - - if ((len > 1) && (val[len-1] == '*')) { - len--; - match = !strncmp(val, str, len); - } else { - match = !strcmp(val, str); - } - - if (match) return 1; - } - - return 0; -} - -void fb_require(const std::string& product, const std::string& var, bool invert, size_t count, - const char** values) { - Status("Checking '" + var + "'"); - - double start = now(); - - std::string var_value; - auto status = fb->GetVar(var, &var_value); - - if (status) { - fprintf(stderr, "getvar:%s FAILED (%s)\n", var.c_str(), fb->Error().c_str()); - die("requirements not met!"); - } - - if (!product.empty()) { - if (product != cur_product) { - double split = now(); - fprintf(stderr, "IGNORE, product is %s required only for %s [%7.3fs]\n", cur_product, - product.c_str(), (split - start)); - return; - } - } - - int yes = match(var_value.c_str(), values, count); - if (invert) yes = !yes; - - if (yes) { - double split = now(); - fprintf(stderr, "OKAY [%7.3fs]\n", (split - start)); - return; - } - - fprintf(stderr, "FAILED\n\n"); - fprintf(stderr, "Device %s is '%s'.\n", var.c_str(), var_value.c_str()); - fprintf(stderr, "Update %s '%s'", invert ? "rejects" : "requires", values[0]); - for (size_t n = 1; n < count; n++) { - fprintf(stderr, " or '%s'", values[n]); - } - fprintf(stderr, ".\n\n"); - die("requirements not met!"); -} - void fb_display(const std::string& label, const std::string& var) { std::string value; auto status = fb->GetVar(var, &value); @@ -210,18 +147,6 @@ void fb_display(const std::string& label, const std::string& var) { fprintf(stderr, "%s: %s\n", label.c_str(), value.c_str()); } -void fb_query_save(const std::string& var, char* dest, uint32_t dest_size) { - std::string value; - auto status = fb->GetVar(var, &value); - - if (status) { - fprintf(stderr, "getvar:%s FAILED (%s)\n", var.c_str(), fb->Error().c_str()); - return; - } - - strncpy(dest, value.c_str(), dest_size); -} - void fb_reboot() { fprintf(stderr, "Rebooting"); fb->Reboot(); |