Merge "Switch fastboot to libziparchive."

This commit is contained in:
Elliott Hughes 2015-03-19 17:20:35 +00:00 committed by Gerrit Code Review
commit 445e5edeeb
2 changed files with 22 additions and 26 deletions

View file

@ -23,7 +23,7 @@ LOCAL_SRC_FILES := protocol.c engine.c bootimg_utils.cpp fastboot.cpp util.c fs.
LOCAL_MODULE := fastboot LOCAL_MODULE := fastboot
LOCAL_MODULE_TAGS := debug LOCAL_MODULE_TAGS := debug
LOCAL_CONLYFLAGS += -std=gnu99 LOCAL_CONLYFLAGS += -std=gnu99
LOCAL_CFLAGS += -Wall -Werror LOCAL_CFLAGS += -Wall -Wextra -Werror
ifeq ($(HOST_OS),linux) ifeq ($(HOST_OS),linux)
LOCAL_SRC_FILES += usb_linux.c util_linux.c LOCAL_SRC_FILES += usb_linux.c util_linux.c
@ -53,9 +53,11 @@ endif
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
$(EXTRA_STATIC_LIBS) \ $(EXTRA_STATIC_LIBS) \
libzipfile \ libziparchive-host \
libext4_utils_host \ libext4_utils_host \
libsparse_host \ libsparse_host \
libutils \
liblog \
libz libz
ifneq ($(HOST_OS),windows) ifneq ($(HOST_OS),windows)

View file

@ -45,7 +45,7 @@
#include <unistd.h> #include <unistd.h>
#include <sparse/sparse.h> #include <sparse/sparse.h>
#include <zipfile/zipfile.h> #include <ziparchive/zip_archive.h>
#include "bootimg_utils.h" #include "bootimg_utils.h"
#include "fastboot.h" #include "fastboot.h"
@ -379,29 +379,24 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
return bdata; return bdata;
} }
static void *unzip_file(zipfile_t zip, const char *name, unsigned *sz) static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
{ {
void *data; ZipEntryName zip_entry_name(name);
zipentry_t entry; ZipEntry zip_entry;
unsigned datasz; if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
entry = lookup_zipentry(zip, name);
if (entry == NULL) {
fprintf(stderr, "archive does not contain '%s'\n", name); fprintf(stderr, "archive does not contain '%s'\n", name);
return 0; return 0;
} }
*sz = get_zipentry_size(entry); *sz = zip_entry.uncompressed_length;
datasz = *sz * 1.001; uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
data = malloc(datasz); if (data == NULL) {
if(data == 0) {
fprintf(stderr, "failed to allocate %d bytes\n", *sz); fprintf(stderr, "failed to allocate %d bytes\n", *sz);
return 0; return 0;
} }
if (decompress_zipentry(entry, data, datasz)) { if (ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length) != 0) {
fprintf(stderr, "failed to unzip '%s' from archive\n", name); fprintf(stderr, "failed to unzip '%s' from archive\n", name);
free(data); free(data);
return 0; return 0;
@ -410,7 +405,7 @@ static void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
return data; return data;
} }
static int unzip_to_file(zipfile_t zip, char *name) static int unzip_to_file(ZipArchiveHandle zip, char *name)
{ {
int fd = fileno(tmpfile()); int fd = fileno(tmpfile());
if (fd < 0) { if (fd < 0) {
@ -693,11 +688,10 @@ void do_flash(usb_handle *usb, const char *pname, const char *fname)
flash_buf(pname, &buf); flash_buf(pname, &buf);
} }
void do_update_signature(zipfile_t zip, char *fn) void do_update_signature(ZipArchiveHandle zip, char *fn)
{ {
void *data;
unsigned sz; unsigned sz;
data = unzip_file(zip, fn, &sz); void* data = unzip_file(zip, fn, &sz);
if (data == 0) return; if (data == 0) return;
fb_queue_download("signature", data, sz); fb_queue_download("signature", data, sz);
fb_queue_command("signature", "installing signature"); fb_queue_command("signature", "installing signature");
@ -709,12 +703,10 @@ void do_update(usb_handle *usb, const char *filename, int erase_first)
fb_queue_query_save("product", cur_product, sizeof(cur_product)); fb_queue_query_save("product", cur_product, sizeof(cur_product));
unsigned zsize; ZipArchiveHandle zip;
void* zdata = load_file(filename, &zsize); if (OpenArchive(filename, &zip) != 0) {
if (zdata == 0) die("failed to load '%s': %s", filename, strerror(errno)); die("failed to open zip file '%s': %s", filename, strerror(errno));
}
zipfile_t zip = init_zipfile(zdata, zsize);
if (zip == 0) die("failed to access zipdata in '%s'");
unsigned sz; unsigned sz;
void* data = unzip_file(zip, "android-info.txt", &sz); void* data = unzip_file(zip, "android-info.txt", &sz);
@ -750,6 +742,8 @@ void do_update(usb_handle *usb, const char *filename, int erase_first)
* program exits. * program exits.
*/ */
} }
CloseArchive(zip);
} }
void do_send_signature(char *fn) void do_send_signature(char *fn)