summaryrefslogtreecommitdiffstats
path: root/updater/updater.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'updater/updater.cpp')
-rw-r--r--updater/updater.cpp98
1 files changed, 55 insertions, 43 deletions
diff --git a/updater/updater.cpp b/updater/updater.cpp
index e956dd557..7327c52e3 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -14,18 +14,26 @@
* limitations under the License.
*/
+#include "updater/updater.h"
+
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include "edify/expr.h"
-#include "updater.h"
-#include "install.h"
-#include "blockimg.h"
-#include "minzip/Zip.h"
-#include "minzip/SysUtil.h"
+#include <string>
+
+#include <android-base/strings.h>
+#include <selinux/label.h>
+#include <selinux/selinux.h>
+#include <ziparchive/zip_archive.h>
+
#include "config.h"
+#include "edify/expr.h"
+#include "otautil/DirUtil.h"
+#include "otautil/SysUtil.h"
+#include "updater/blockimg.h"
+#include "updater/install.h"
// Generated by the makefile, this function defines the
// RegisterDeviceExtensions() function, which calls all the
@@ -77,28 +85,35 @@ int main(int argc, char** argv) {
printf("failed to map package %s\n", argv[3]);
return 3;
}
- ZipArchive za;
- int err;
- err = mzOpenZipArchive(map.addr, map.length, &za);
- if (err != 0) {
+ ZipArchiveHandle za;
+ int open_err = OpenArchiveFromMemory(map.addr, map.length, argv[3], &za);
+ if (open_err != 0) {
printf("failed to open package %s: %s\n",
- argv[3], strerror(err));
+ argv[3], ErrorCodeString(open_err));
+ CloseArchive(za);
return 3;
}
- ota_io_init(&za);
-
- const ZipEntry* script_entry = mzFindZipEntry(&za, SCRIPT_NAME);
- if (script_entry == NULL) {
- printf("failed to find %s in %s\n", SCRIPT_NAME, package_filename);
+ ota_io_init(za);
+
+ ZipString script_name(SCRIPT_NAME);
+ ZipEntry script_entry;
+ int find_err = FindEntry(za, script_name, &script_entry);
+ if (find_err != 0) {
+ printf("failed to find %s in %s: %s\n", SCRIPT_NAME, package_filename,
+ ErrorCodeString(find_err));
+ CloseArchive(za);
return 4;
}
- char* script = reinterpret_cast<char*>(malloc(script_entry->uncompLen+1));
- if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) {
- printf("failed to read script from package\n");
+ std::string script;
+ script.resize(script_entry.uncompressed_length);
+ int extract_err = ExtractToMemory(za, &script_entry, reinterpret_cast<uint8_t*>(&script[0]),
+ script_entry.uncompressed_length);
+ if (extract_err != 0) {
+ printf("failed to read script from package: %s\n", ErrorCodeString(extract_err));
+ CloseArchive(za);
return 5;
}
- script[script_entry->uncompLen] = '\0';
// Configure edify's functions.
@@ -106,15 +121,15 @@ int main(int argc, char** argv) {
RegisterInstallFunctions();
RegisterBlockImageFunctions();
RegisterDeviceExtensions();
- FinishRegistration();
// Parse the script.
Expr* root;
int error_count = 0;
- int error = parse_string(script, &root, &error_count);
+ int error = parse_string(script.c_str(), &root, &error_count);
if (error != 0 || error_count > 0) {
printf("%d parse errors\n", error_count);
+ CloseArchive(za);
return 6;
}
@@ -132,15 +147,12 @@ int main(int argc, char** argv) {
UpdaterInfo updater_info;
updater_info.cmd_pipe = cmd_pipe;
- updater_info.package_zip = &za;
+ updater_info.package_zip = za;
updater_info.version = atoi(version);
updater_info.package_zip_addr = map.addr;
updater_info.package_zip_len = map.length;
- State state;
- state.cookie = &updater_info;
- state.script = script;
- state.errmsg = NULL;
+ State state(script, &updater_info);
if (argc == 5) {
if (strcmp(argv[4], "retry") == 0) {
@@ -150,29 +162,29 @@ int main(int argc, char** argv) {
}
}
- char* result = Evaluate(&state, root);
+ std::string result;
+ bool status = Evaluate(&state, root, &result);
if (have_eio_error) {
fprintf(cmd_pipe, "retry_update\n");
}
- if (result == NULL) {
- if (state.errmsg == NULL) {
+ if (!status) {
+ if (state.errmsg.empty()) {
printf("script aborted (no error message)\n");
fprintf(cmd_pipe, "ui_print script aborted (no error message)\n");
} else {
- printf("script aborted: %s\n", state.errmsg);
- char* line = strtok(state.errmsg, "\n");
- while (line) {
+ printf("script aborted: %s\n", state.errmsg.c_str());
+ const std::vector<std::string> lines = android::base::Split(state.errmsg, "\n");
+ for (const std::string& line : lines) {
// Parse the error code in abort message.
// Example: "E30: This package is for bullhead devices."
- if (*line == 'E') {
- if (sscanf(line, "E%u: ", &state.error_code) != 1) {
- printf("Failed to parse error code: [%s]\n", line);
+ if (!line.empty() && line[0] == 'E') {
+ if (sscanf(line.c_str(), "E%u: ", &state.error_code) != 1) {
+ printf("Failed to parse error code: [%s]\n", line.c_str());
}
}
- fprintf(cmd_pipe, "ui_print %s\n", line);
- line = strtok(NULL, "\n");
+ fprintf(cmd_pipe, "ui_print %s\n", line.c_str());
}
fprintf(cmd_pipe, "ui_print\n");
}
@@ -186,18 +198,18 @@ int main(int argc, char** argv) {
}
}
- free(state.errmsg);
+ if (updater_info.package_zip) {
+ CloseArchive(updater_info.package_zip);
+ }
return 7;
} else {
- fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result);
- free(result);
+ fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result.c_str());
}
if (updater_info.package_zip) {
- mzCloseZipArchive(updater_info.package_zip);
+ CloseArchive(updater_info.package_zip);
}
sysReleaseMap(&map);
- free(script);
return 0;
}