summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-03-19 19:17:40 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-19 19:17:40 +0000
commit5b40fcbd1dbac7e9d0534154265230ba87dfb39e (patch)
tree9c981575a252b7595f181c77c10e24ae6ae14f27 /fastboot
parentddaabcf22f678abb3f949667cac458935eb17941 (diff)
parenta782173a26f192fe9f51e1ee53e8d329501df409 (diff)
downloadsystem_core-5b40fcbd1dbac7e9d0534154265230ba87dfb39e.zip
system_core-5b40fcbd1dbac7e9d0534154265230ba87dfb39e.tar.gz
system_core-5b40fcbd1dbac7e9d0534154265230ba87dfb39e.tar.bz2
am a782173a: am 261a82a6: Merge "Switch fastboot to ExtractEntryToFile."
* commit 'a782173a26f192fe9f51e1ee53e8d329501df409': Switch fastboot to ExtractEntryToFile.
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/fastboot.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index a1847f6..a25d316 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -369,12 +369,12 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
return bdata;
}
-static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
+static void* unzip_file(ZipArchiveHandle zip, const char* entry_name, unsigned* sz)
{
- ZipEntryName zip_entry_name(name);
+ ZipEntryName zip_entry_name(entry_name);
ZipEntry zip_entry;
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
- fprintf(stderr, "archive does not contain '%s'\n", name);
+ fprintf(stderr, "archive does not contain '%s'\n", entry_name);
return 0;
}
@@ -382,12 +382,13 @@ static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
if (data == NULL) {
- fprintf(stderr, "failed to allocate %d bytes\n", *sz);
+ fprintf(stderr, "failed to allocate %u bytes for '%s'\n", *sz, entry_name);
return 0;
}
- if (ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length) != 0) {
- fprintf(stderr, "failed to unzip '%s' from archive\n", name);
+ int error = ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length);
+ if (error != 0) {
+ fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
free(data);
return 0;
}
@@ -395,24 +396,28 @@ static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
return data;
}
-static int unzip_to_file(ZipArchiveHandle zip, char *name)
-{
- int fd = fileno(tmpfile());
- if (fd < 0) {
+static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) {
+ FILE* fp = tmpfile();
+ if (fp == NULL) {
+ fprintf(stderr, "failed to create temporary file for '%s': %s\n",
+ entry_name, strerror(errno));
return -1;
}
- unsigned sz;
- void* data = unzip_file(zip, name, &sz);
- if (data == 0) {
+ ZipEntryName zip_entry_name(entry_name);
+ ZipEntry zip_entry;
+ if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
+ fprintf(stderr, "archive does not contain '%s'\n", entry_name);
return -1;
}
- if (write(fd, data, sz) != (ssize_t)sz) {
- fd = -1;
+ int fd = fileno(fp);
+ int error = ExtractEntryToFile(zip, &zip_entry, fd);
+ if (error != 0) {
+ fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
+ return -1;
}
- free(data);
lseek(fd, 0, SEEK_SET);
return fd;
}
@@ -694,8 +699,9 @@ void do_update(usb_handle *usb, const char *filename, int erase_first)
fb_queue_query_save("product", cur_product, sizeof(cur_product));
ZipArchiveHandle zip;
- if (OpenArchive(filename, &zip) != 0) {
- die("failed to open zip file '%s': %s", filename, strerror(errno));
+ int error = OpenArchive(filename, &zip);
+ if (error != 0) {
+ die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
}
unsigned sz;