aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-09-08 22:10:11 -0500
committerTianjie Xu2016-10-17 19:41:51 -0500
commit8cf5c8f60f51049278b08ae4cbc31df397b651fd (patch)
treea49e8f62581f0fbc8f7e352ee780220130435a6f /install.cpp
parent2b17b24ae5eccd6c472c06abde93b5b83950c658 (diff)
downloadplatform-bootable-recovery-8cf5c8f60f51049278b08ae4cbc31df397b651fd.tar.gz
platform-bootable-recovery-8cf5c8f60f51049278b08ae4cbc31df397b651fd.tar.xz
platform-bootable-recovery-8cf5c8f60f51049278b08ae4cbc31df397b651fd.zip
Replace minzip with libziparchive
Clean up the duplicated codes that handle the zip files in bootable/recovery; and rename the library of the remaining utility functions to libotautil. Test: Update package installed successfully on angler. Bug: 19472796 Change-Id: Iea8962fcf3004473cb0322b6bb3a9ea3ca7f679e
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/install.cpp b/install.cpp
index 72c922d5..c9871523 100644
--- a/install.cpp
+++ b/install.cpp
@@ -32,13 +32,13 @@
32#include <android-base/parseint.h> 32#include <android-base/parseint.h>
33#include <android-base/stringprintf.h> 33#include <android-base/stringprintf.h>
34#include <android-base/strings.h> 34#include <android-base/strings.h>
35#include <ziparchive/zip_archive.h>
35 36
36#include "common.h" 37#include "common.h"
37#include "error_code.h" 38#include "error_code.h"
38#include "install.h" 39#include "install.h"
39#include "minui/minui.h" 40#include "minui/minui.h"
40#include "minzip/SysUtil.h" 41#include "otautil/SysUtil.h"
41#include "minzip/Zip.h"
42#include "roots.h" 42#include "roots.h"
43#include "ui.h" 43#include "ui.h"
44#include "verifier.h" 44#include "verifier.h"
@@ -72,15 +72,17 @@ static int parse_build_number(const std::string& str) {
72} 72}
73 73
74// Read the build.version.incremental of src/tgt from the metadata and log it to last_install. 74// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
75static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { 75static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) {
76 const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); 76 ZipString metadata_path(METADATA_PATH);
77 if (meta_entry == nullptr) { 77 ZipEntry meta_entry;
78 if (FindEntry(zip, metadata_path, &meta_entry) != 0) {
78 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; 79 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
79 return; 80 return;
80 } 81 }
81 82
82 std::string meta_data(meta_entry->uncompLen, '\0'); 83 std::string meta_data(meta_entry.uncompressed_length, '\0');
83 if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) { 84 if (ExtractToMemory(zip, &meta_entry, reinterpret_cast<uint8_t*>(&meta_data[0]),
85 meta_entry.uncompressed_length) != 0) {
84 LOG(ERROR) << "Failed to read metadata in update package"; 86 LOG(ERROR) << "Failed to read metadata in update package";
85 return; 87 return;
86 } 88 }
@@ -109,15 +111,14 @@ static void read_source_target_build(ZipArchive* zip, std::vector<std::string>&
109 111
110// If the package contains an update binary, extract it and run it. 112// If the package contains an update binary, extract it and run it.
111static int 113static int
112try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, 114try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache,
113 std::vector<std::string>& log_buffer, int retry_count) 115 std::vector<std::string>& log_buffer, int retry_count)
114{ 116{
115 read_source_target_build(zip, log_buffer); 117 read_source_target_build(zip, log_buffer);
116 118
117 const ZipEntry* binary_entry = 119 ZipString binary_name(ASSUMED_UPDATE_BINARY_NAME);
118 mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME); 120 ZipEntry binary_entry;
119 if (binary_entry == NULL) { 121 if (FindEntry(zip, binary_name, &binary_entry) != 0) {
120 mzCloseZipArchive(zip);
121 return INSTALL_CORRUPT; 122 return INSTALL_CORRUPT;
122 } 123 }
123 124
@@ -126,15 +127,14 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
126 int fd = creat(binary, 0755); 127 int fd = creat(binary, 0755);
127 if (fd < 0) { 128 if (fd < 0) {
128 PLOG(ERROR) << "Can't make " << binary; 129 PLOG(ERROR) << "Can't make " << binary;
129 mzCloseZipArchive(zip);
130 return INSTALL_ERROR; 130 return INSTALL_ERROR;
131 } 131 }
132 bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); 132 int error = ExtractEntryToFile(zip, &binary_entry, fd);
133 close(fd); 133 close(fd);
134 mzCloseZipArchive(zip);
135 134
136 if (!ok) { 135 if (error != 0) {
137 LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME; 136 LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME
137 << " : " << ErrorCodeString(error);
138 return INSTALL_ERROR; 138 return INSTALL_ERROR;
139 } 139 }
140 140
@@ -326,13 +326,14 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
326 } 326 }
327 327
328 // Try to open the package. 328 // Try to open the package.
329 ZipArchive zip; 329 ZipArchiveHandle zip;
330 err = mzOpenZipArchive(map.addr, map.length, &zip); 330 err = OpenArchiveFromMemory(map.addr, map.length, path, &zip);
331 if (err != 0) { 331 if (err != 0) {
332 LOG(ERROR) << "Can't open " << path; 332 LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err);
333 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); 333 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
334 334
335 sysReleaseMap(&map); 335 sysReleaseMap(&map);
336 CloseArchive(zip);
336 return INSTALL_CORRUPT; 337 return INSTALL_CORRUPT;
337 } 338 }
338 339
@@ -342,12 +343,12 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
342 ui->Print("Retry attempt: %d\n", retry_count); 343 ui->Print("Retry attempt: %d\n", retry_count);
343 } 344 }
344 ui->SetEnableReboot(false); 345 ui->SetEnableReboot(false);
345 int result = try_update_binary(path, &zip, wipe_cache, log_buffer, retry_count); 346 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count);
346 ui->SetEnableReboot(true); 347 ui->SetEnableReboot(true);
347 ui->Print("\n"); 348 ui->Print("\n");
348 349
349 sysReleaseMap(&map); 350 sysReleaseMap(&map);
350 351 CloseArchive(zip);
351 return result; 352 return result;
352} 353}
353 354