diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-08 20:55:08 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-08 20:55:08 (EDT) |
commit | ab74f60d3b8631633ff4164c57fbfb282a1aa7f3 (patch) | |
tree | 61e515b8338c0074d8f3815e9fb5456bcb1e8b33 | |
parent | b6d36859246e1ea432911169d1f325df1479eac7 (diff) |
gzip: Separate last compression from freeing
-rw-r--r-- | src/gzip.c | 18 | ||||
-rw-r--r-- | src/gzip.h | 3 | ||||
-rw-r--r-- | src/opk/write.c | 1 |
3 files changed, 19 insertions, 3 deletions
@@ -229,6 +229,21 @@ opkg_opk_gzip_written(struct opkg_opk_gzip *gzip) } int +opkg_opk_gzip_finish_write(struct opkg_opk_gzip *gzip) +{ + /* Sanity check */ + if (gzip->dir != _OPKG_OPK_GZIP_DIR_WRITE) { + return OPKG_OPK_ERROR; + } + + if (gzip->written > 0 && _opkg_opk_gzip_write(gzip, NULL, 0, 1) != + OPKG_OPK_END) { + return OPKG_OPK_ERROR; + } + return OPKG_OPK_OK; +} + +int opkg_opk_gzip_free(struct opkg_opk_gzip *gzip) { int ret; @@ -239,9 +254,6 @@ opkg_opk_gzip_free(struct opkg_opk_gzip *gzip) ret = OPKG_OPK_ERROR; } } else { - if (_opkg_opk_gzip_write(gzip, NULL, 0, 1) != OPKG_OPK_END) { - ret = OPKG_OPK_ERROR; - } if (deflateEnd(&gzip->stream) != Z_OK) { ret = OPKG_OPK_ERROR; } @@ -68,6 +68,9 @@ opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size); size_t opkg_opk_gzip_written(struct opkg_opk_gzip *gzip); +int +opkg_opk_gzip_finish_write(struct opkg_opk_gzip *gzip); + /* * Frees a decompression structure. * Parameters: diff --git a/src/opk/write.c b/src/opk/write.c index a00cf77..9c710f6 100644 --- a/src/opk/write.c +++ b/src/opk/write.c @@ -125,6 +125,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name) out3: opkg_opk_ustar_free(opk->outer_ustar); out2: + opkg_opk_gzip_finish_write(opk->outer_gzip); opkg_opk_gzip_free(opk->outer_gzip); out1: fclose(opk->file); |