diff options
author | Tianjie Xu <xunchang@google.com> | 2016-10-19 00:05:21 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-10-19 00:05:21 +0200 |
commit | 434697f06b7432a2358550eadd74fb97d617035c (patch) | |
tree | c24e3fb0f24bd693e63bfed48e497730164df079 /updater | |
parent | Merge "Change StringValue to use std::string" am: 2b17b24ae5 (diff) | |
parent | resolve merge conflicts of 6fba98c to stage-aosp-master (diff) | |
download | android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar.gz android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar.bz2 android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar.lz android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar.xz android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.tar.zst android_bootable_recovery-434697f06b7432a2358550eadd74fb97d617035c.zip |
Diffstat (limited to '')
-rw-r--r-- | updater/Android.mk | 4 | ||||
-rw-r--r-- | updater/blockimg.cpp | 73 | ||||
-rw-r--r-- | updater/include/updater/updater.h | 4 | ||||
-rw-r--r-- | updater/install.cpp | 38 | ||||
-rw-r--r-- | updater/updater.cpp | 53 |
5 files changed, 87 insertions, 85 deletions
diff --git a/updater/Android.mk b/updater/Android.mk index 33e97385e..3c1d0d41f 100644 --- a/updater/Android.mk +++ b/updater/Android.mk @@ -25,7 +25,9 @@ tune2fs_static_libraries := \ updater_common_static_libraries := \ libapplypatch \ libedify \ - libminzip \ + libziparchive \ + libotautil \ + libutils \ libmounts \ libotafault \ libext4_utils_static \ diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 5f9b437fe..f08ca5b0c 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -33,21 +33,21 @@ #include <unistd.h> #include <fec/io.h> -#include <map> #include <memory> #include <string> +#include <unordered_map> #include <vector> #include <android-base/parseint.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> +#include <ziparchive/zip_archive.h> #include "applypatch/applypatch.h" #include "edify/expr.h" #include "error_code.h" #include "updater/install.h" #include "openssl/sha.h" -#include "minzip/Hash.h" #include "ota_io.h" #include "print_sha1.h" #include "updater/updater.h" @@ -71,7 +71,7 @@ struct RangeSet { static CauseCode failure_type = kNoCause; static bool is_retry = false; -static std::map<std::string, RangeSet> stash_map; +static std::unordered_map<std::string, RangeSet> stash_map; static void parse_range(const std::string& range_text, RangeSet& rs) { @@ -300,8 +300,8 @@ static ssize_t RangeSinkWrite(const uint8_t* data, ssize_t size, void* token) { // rss and signals the condition again. struct NewThreadInfo { - ZipArchive* za; - const ZipEntry* entry; + ZipArchiveHandle za; + ZipEntry entry; RangeSinkState* rss; @@ -309,7 +309,7 @@ struct NewThreadInfo { pthread_cond_t cv; }; -static bool receive_new_data(const unsigned char* data, int size, void* cookie) { +static bool receive_new_data(const uint8_t* data, size_t size, void* cookie) { NewThreadInfo* nti = reinterpret_cast<NewThreadInfo*>(cookie); while (size > 0) { @@ -342,7 +342,7 @@ static bool receive_new_data(const unsigned char* data, int size, void* cookie) static void* unzip_new_data(void* cookie) { NewThreadInfo* nti = (NewThreadInfo*) cookie; - mzProcessZipEntryContents(nti->za, nti->entry, receive_new_data, nti); + ProcessZipEntryContents(nti->za, &nti->entry, receive_new_data, nti); return nullptr; } @@ -1351,28 +1351,6 @@ struct Command { CommandFunction f; }; -// CompareCommands and CompareCommandNames are for the hash table - -static int CompareCommands(const void* c1, const void* c2) { - return strcmp(((const Command*) c1)->name, ((const Command*) c2)->name); -} - -static int CompareCommandNames(const void* c1, const void* c2) { - return strcmp(((const Command*) c1)->name, (const char*) c2); -} - -// HashString is used to hash command names for the hash table - -static unsigned int HashString(const char *s) { - unsigned int hash = 0; - if (s) { - while (*s) { - hash = hash * 33 + *s++; - } - } - return hash; -} - // args: // - block device (or file) to modify in-place // - transfer list (blob) @@ -1429,21 +1407,23 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg } FILE* cmd_pipe = ui->cmd_pipe; - ZipArchive* za = ui->package_zip; + ZipArchiveHandle za = ui->package_zip; if (cmd_pipe == nullptr || za == nullptr) { return StringValue(""); } - const ZipEntry* patch_entry = mzFindZipEntry(za, patch_data_fn->data.c_str()); - if (patch_entry == nullptr) { + ZipString path_data(patch_data_fn->data.c_str()); + ZipEntry patch_entry; + if (FindEntry(za, path_data, &patch_entry) != 0) { fprintf(stderr, "%s(): no file \"%s\" in package", name, patch_data_fn->data.c_str()); return StringValue(""); } - params.patch_start = ui->package_zip_addr + mzGetZipEntryOffset(patch_entry); - const ZipEntry* new_entry = mzFindZipEntry(za, new_data_fn->data.c_str()); - if (new_entry == nullptr) { + params.patch_start = ui->package_zip_addr + patch_entry.offset; + ZipString new_data(new_data_fn->data.c_str()); + ZipEntry new_entry; + if (FindEntry(za, new_data, &new_entry) != 0) { fprintf(stderr, "%s(): no file \"%s\" in package", name, new_data_fn->data.c_str()); return StringValue(""); } @@ -1526,13 +1506,15 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg start += 2; } - // Build a hash table of the available commands - HashTable* cmdht = mzHashTableCreate(cmdcount, nullptr); - std::unique_ptr<HashTable, decltype(&mzHashTableFree)> cmdht_holder(cmdht, mzHashTableFree); - + // Build a map of the available commands + std::unordered_map<std::string, const Command*> cmd_map; for (size_t i = 0; i < cmdcount; ++i) { - unsigned int cmdhash = HashString(commands[i].name); - mzHashTableLookup(cmdht, cmdhash, (void*) &commands[i], CompareCommands, true); + if (cmd_map.find(commands[i].name) != cmd_map.end()) { + fprintf(stderr, "Error: command [%s] already exists in the cmd map.\n", + commands[i].name); + return StringValue(strdup("")); + } + cmd_map[commands[i].name] = &commands[i]; } int rc = -1; @@ -1549,16 +1531,13 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg params.cmdname = params.tokens[params.cpos++].c_str(); params.cmdline = line_str.c_str(); - unsigned int cmdhash = HashString(params.cmdname); - const Command* cmd = reinterpret_cast<const Command*>(mzHashTableLookup(cmdht, cmdhash, - const_cast<char*>(params.cmdname), CompareCommandNames, - false)); - - if (cmd == nullptr) { + if (cmd_map.find(params.cmdname) == cmd_map.end()) { fprintf(stderr, "unexpected command [%s]\n", params.cmdname); goto pbiudone; } + const Command* cmd = cmd_map[params.cmdname]; + if (cmd->f != nullptr && cmd->f(params) == -1) { fprintf(stderr, "failed to execute command [%s]\n", line_str.c_str()); goto pbiudone; diff --git a/updater/include/updater/updater.h b/updater/include/updater/updater.h index d3a09b93d..f4a2fe874 100644 --- a/updater/include/updater/updater.h +++ b/updater/include/updater/updater.h @@ -18,11 +18,11 @@ #define _UPDATER_UPDATER_H_ #include <stdio.h> -#include "minzip/Zip.h" +#include <ziparchive/zip_archive.h> typedef struct { FILE* cmd_pipe; - ZipArchive* package_zip; + ZipArchiveHandle package_zip; int version; uint8_t* package_zip_addr; diff --git a/updater/install.cpp b/updater/install.cpp index d723b3880..a41c5db3c 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -33,6 +33,7 @@ #include <sys/xattr.h> #include <time.h> #include <unistd.h> +#include <utime.h> #include <memory> #include <string> @@ -48,14 +49,16 @@ #include <openssl/sha.h> #include <selinux/label.h> #include <selinux/selinux.h> +#include <ziparchive/zip_archive.h> #include "applypatch/applypatch.h" #include "bootloader.h" #include "edify/expr.h" #include "error_code.h" -#include "minzip/DirUtil.h" #include "mounts.h" #include "ota_io.h" +#include "otautil/DirUtil.h" +#include "otautil/ZipUtil.h" #include "print_sha1.h" #include "tune2fs.h" #include "updater/updater.h" @@ -465,14 +468,13 @@ Value* PackageExtractDirFn(const char* name, State* state, char* dest_path; if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL; - ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; + ZipArchiveHandle za = ((UpdaterInfo*)(state->cookie))->package_zip; // To create a consistent system image, never use the clock for timestamps. struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default - bool success = mzExtractRecursive(za, zip_path, dest_path, - ×tamp, - NULL, NULL, sehandle); + bool success = ExtractPackageRecursive(za, zip_path, dest_path, ×tamp, sehandle); + free(zip_path); free(dest_path); return StringValue(success ? "t" : ""); @@ -495,14 +497,15 @@ Value* PackageExtractFileFn(const char* name, State* state, if (argc == 2) { // The two-argument version extracts to a file. - ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; + ZipArchiveHandle za = ((UpdaterInfo*)(state->cookie))->package_zip; char* zip_path; char* dest_path; if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL; - const ZipEntry* entry = mzFindZipEntry(za, zip_path); - if (entry == NULL) { + ZipString zip_string_path(zip_path); + ZipEntry entry; + if (FindEntry(za, zip_string_path, &entry) != 0) { printf("%s: no %s in package\n", name, zip_path); goto done2; } @@ -514,7 +517,7 @@ Value* PackageExtractFileFn(const char* name, State* state, printf("%s: can't open %s for write: %s\n", name, dest_path, strerror(errno)); goto done2; } - success = mzExtractZipEntryToFile(za, entry, fd); + success = ExtractEntryToFile(za, &entry, fd); if (ota_fsync(fd) == -1) { printf("fsync of \"%s\" failed: %s\n", dest_path, strerror(errno)); success = false; @@ -538,16 +541,21 @@ Value* PackageExtractFileFn(const char* name, State* state, Value* v = new Value(VAL_INVALID, ""); - ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; - const ZipEntry* entry = mzFindZipEntry(za, zip_path); - if (entry == NULL) { + ZipArchiveHandle za = ((UpdaterInfo*)(state->cookie))->package_zip; + ZipString zip_string_path(zip_path); + ZipEntry entry; + if (FindEntry(za, zip_string_path, &entry) != 0) { printf("%s: no %s in package\n", name, zip_path); goto done1; } - v->data.resize(mzGetZipEntryUncompLen(entry)); - success = mzExtractZipEntryToBuffer(za, entry, - reinterpret_cast<unsigned char *>(&v->data[0])); + v->data.resize(entry.uncompressed_length); + if (ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&v->data[0]), + v->data.size()) != 0) { + printf("%s: faled to extract %zu bytes to memory\n", name, v->data.size()); + } else { + success = true; + } done1: free(zip_path); diff --git a/updater/updater.cpp b/updater/updater.cpp index 47696b80c..7327c52e3 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -21,14 +21,17 @@ #include <stdlib.h> #include <string.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 "minzip/SysUtil.h" -#include "minzip/Zip.h" +#include "otautil/DirUtil.h" +#include "otautil/SysUtil.h" #include "updater/blockimg.h" #include "updater/install.h" @@ -82,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. @@ -116,9 +126,10 @@ int main(int argc, char** argv) { 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; } @@ -136,7 +147,7 @@ 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; @@ -187,16 +198,18 @@ int main(int argc, char** argv) { } } + 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.c_str()); } if (updater_info.package_zip) { - mzCloseZipArchive(updater_info.package_zip); + CloseArchive(updater_info.package_zip); } sysReleaseMap(&map); - free(script); return 0; } |