am 261a82a6: Merge "Switch fastboot to ExtractEntryToFile."
* commit '261a82a668cfcbf970b2cf3dd5a79d5342b0e387': Switch fastboot to ExtractEntryToFile.
This commit is contained in:
commit
a782173a26
1 changed files with 24 additions and 18 deletions
|
|
@ -379,12 +379,12 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
|
||||||
return bdata;
|
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;
|
ZipEntry zip_entry;
|
||||||
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -392,12 +392,13 @@ static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
|
||||||
|
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
|
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
|
||||||
if (data == NULL) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length) != 0) {
|
int error = ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length);
|
||||||
fprintf(stderr, "failed to unzip '%s' from archive\n", name);
|
if (error != 0) {
|
||||||
|
fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -405,24 +406,28 @@ static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unzip_to_file(ZipArchiveHandle zip, char *name)
|
static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) {
|
||||||
{
|
FILE* fp = tmpfile();
|
||||||
int fd = fileno(tmpfile());
|
if (fp == NULL) {
|
||||||
if (fd < 0) {
|
fprintf(stderr, "failed to create temporary file for '%s': %s\n",
|
||||||
|
entry_name, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sz;
|
ZipEntryName zip_entry_name(entry_name);
|
||||||
void* data = unzip_file(zip, name, &sz);
|
ZipEntry zip_entry;
|
||||||
if (data == 0) {
|
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
|
||||||
|
fprintf(stderr, "archive does not contain '%s'\n", entry_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, data, sz) != (ssize_t)sz) {
|
int fd = fileno(fp);
|
||||||
fd = -1;
|
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);
|
lseek(fd, 0, SEEK_SET);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
@ -704,8 +709,9 @@ 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));
|
||||||
|
|
||||||
ZipArchiveHandle zip;
|
ZipArchiveHandle zip;
|
||||||
if (OpenArchive(filename, &zip) != 0) {
|
int error = OpenArchive(filename, &zip);
|
||||||
die("failed to open zip file '%s': %s", filename, strerror(errno));
|
if (error != 0) {
|
||||||
|
die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sz;
|
unsigned sz;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue