Refactored zip support for pilerexport

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2020-10-31 07:58:52 +01:00
parent 5331297c55
commit b5a8255be1

View File

@ -326,34 +326,14 @@ int write_to_zip_file(char *filename){
return ret; return ret;
} }
int fd = open(filename, O_RDONLY); zip_source_t *zs = zip_source_file(z, filename, 0, 0);
if(fd == -1){ if(zs && zip_file_add(z, filename, zs, ZIP_FL_ENC_UTF_8) >= 0){
printf("cannot open: %s\n", filename);
return ret;
}
struct stat st;
if(fstat(fd, &st)){
close(fd);
return ret;
}
char *addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
if(addr == MAP_FAILED) return ret;
zip_source_t *zs = zip_source_buffer(z, addr, st.st_size, 0);
if(zip_file_add(z, filename, zs, ZIP_FL_ENC_UTF_8) == -1){
printf("error adding file %s: %s\n", filename, zip_strerror(z));
zip_source_free(zs);
} else {
ret = OK; ret = OK;
} else {
printf("error adding file %s: %s\n", filename, zip_strerror(z));
} }
zip_close(z); zip_close(z);
munmap(addr, st.st_size);
return ret; return ret;
} }