diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-07-16 13:47:26 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-07-16 13:47:26 +0300 |
commit | 0f6d96a4f5a904fd95b96e13715b50befa6a0ee9 (patch) | |
tree | e43022707015019f093c14fd1afd2440d6d75ead /src | |
parent | 6715a0ba12af54767ba889de07afe3543b7c1543 (diff) | |
download | aports-0f6d96a4f5a904fd95b96e13715b50befa6a0ee9.tar.bz2 aports-0f6d96a4f5a904fd95b96e13715b50befa6a0ee9.tar.xz |
gzip: always autoclose the inner stream
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_archive.h | 1 | ||||
-rw-r--r-- | src/apk_io.h | 7 | ||||
-rw-r--r-- | src/archive.c | 13 | ||||
-rw-r--r-- | src/database.c | 19 | ||||
-rw-r--r-- | src/gunzip.c | 7 | ||||
-rw-r--r-- | src/index.c | 2 | ||||
-rw-r--r-- | src/io.c | 2 | ||||
-rw-r--r-- | src/package.c | 8 | ||||
-rw-r--r-- | src/url.c | 4 |
9 files changed, 22 insertions, 41 deletions
diff --git a/src/apk_archive.h b/src/apk_archive.h index d3b787db5a..f1787dc507 100644 --- a/src/apk_archive.h +++ b/src/apk_archive.h @@ -21,7 +21,6 @@ typedef int (*apk_archive_entry_parser)(void *ctx, struct apk_istream *istream); int apk_parse_tar(struct apk_istream *, apk_archive_entry_parser parser, void *ctx); -int apk_parse_tar_gz(struct apk_bstream *, apk_archive_entry_parser parser, void *ctx); int apk_write_tar_entry(struct apk_ostream *, const struct apk_file_info *ae, char *data); int apk_archive_entry_extract(const struct apk_file_info *ae, diff --git a/src/apk_io.h b/src/apk_io.h index 1fe4f2c5c4..49d9fcfa35 100644 --- a/src/apk_io.h +++ b/src/apk_io.h @@ -51,12 +51,11 @@ struct apk_ostream { typedef int (*apk_multipart_cb)(void *ctx, EVP_MD_CTX *mdctx, int part); -struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *, int, +struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *, apk_multipart_cb cb, void *ctx); -static inline struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs, - int autoclose) +static inline struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs) { - return apk_bstream_gunzip_mpart(bs, autoclose, NULL, NULL); + return apk_bstream_gunzip_mpart(bs, NULL, NULL); } struct apk_ostream *apk_ostream_gzip(struct apk_ostream *); diff --git a/src/archive.c b/src/archive.c index 0a53792cf1..8e55295b5e 100644 --- a/src/archive.c +++ b/src/archive.c @@ -255,19 +255,6 @@ int apk_write_tar_entry(struct apk_ostream *os, const struct apk_file_info *ae, return 0; } -int apk_parse_tar_gz(struct apk_bstream *bs, apk_archive_entry_parser parser, - void *ctx) -{ - struct apk_istream *is; - int rc; - - is = apk_bstream_gunzip(bs, FALSE); - rc = apk_parse_tar(is, parser, ctx); - is->close(is); - - return rc; -} - int apk_archive_entry_extract(const struct apk_file_info *ae, struct apk_istream *is, const char *fn, apk_progress_cb cb, diff --git a/src/database.c b/src/database.c index 4daa66a6e4..2a15385a15 100644 --- a/src/database.c +++ b/src/database.c @@ -1135,7 +1135,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository) } else { bs = apk_repository_file_open(repo, apk_index_gz); } - bs = apk_bstream_from_istream(apk_bstream_gunzip(bs, TRUE)); + bs = apk_bstream_from_istream(apk_bstream_gunzip(bs)); if (bs == NULL) { apk_warning("Failed to open index for %s", repo->url); return -1; @@ -1377,7 +1377,6 @@ static int apk_db_unpack_pkg(struct apk_database *db, struct apk_istream *tar; char pkgname[256], file[256]; int i, need_copy = FALSE; - size_t length; snprintf(pkgname, sizeof(pkgname), "%s-%s.apk", newpkg->name->name, newpkg->version); @@ -1433,10 +1432,10 @@ static int apk_db_unpack_pkg(struct apk_database *db, .cb_ctx = cb_ctx, }; - tar = apk_bstream_gunzip_mpart(bs, FALSE, apk_db_gzip_part, &ctx); + tar = apk_bstream_gunzip_mpart(bs, apk_db_gzip_part, &ctx); if (apk_parse_tar(tar, apk_db_install_archive_entry, &ctx) != 0) goto err_close; - bs->close(bs, &length); + tar->close(tar); /* Check the package checksum */ if (apk_checksum_compare(&ctx.data_csum, &newpkg->csum) != 0) @@ -1444,14 +1443,10 @@ static int apk_db_unpack_pkg(struct apk_database *db, newpkg->name->name, newpkg->version); if (need_copy) { - if (length == newpkg->size) { - char file2[256]; - apk_db_cache_get_name(file2, sizeof(file2), db, - &newpkg->csum, pkgname, FALSE); - rename(file, file2); - } else { - unlink(file); - } + char file2[256]; + apk_db_cache_get_name(file2, sizeof(file2), db, + &newpkg->csum, pkgname, FALSE); + rename(file, file2); } return 0; diff --git a/src/gunzip.c b/src/gunzip.c index 010d45ef37..af906d1e51 100644 --- a/src/gunzip.c +++ b/src/gunzip.c @@ -22,7 +22,6 @@ struct apk_gzip_istream { struct apk_bstream *bs; z_stream zs; int z_err; - int autoclose; EVP_MD_CTX mdctx; void *mdblock; @@ -104,12 +103,11 @@ static void gz_close(void *stream) if (gis->cb != NULL) EVP_MD_CTX_cleanup(&gis->mdctx); inflateEnd(&gis->zs); - if (gis->autoclose) - gis->bs->close(gis->bs, NULL); + gis->bs->close(gis->bs, NULL); free(gis); } -struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs, int autoclose, +struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs, apk_multipart_cb cb, void *ctx) { struct apk_gzip_istream *gis; @@ -126,7 +124,6 @@ struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs, int autoclo .is.close = gz_close, .bs = bs, .z_err = 0, - .autoclose = autoclose, .cb = cb, .cbctx = ctx, }; diff --git a/src/index.c b/src/index.c index 62460f7bfb..d7402f9ee5 100644 --- a/src/index.c +++ b/src/index.c @@ -48,7 +48,7 @@ static int index_read_file(struct apk_database *db, struct index_ctx *ictx) if (apk_file_get_info(ictx->index, APK_CHECKSUM_NONE, &fi) < 0) return -1; ictx->index_mtime = fi.mtime; - bs = apk_bstream_from_istream(apk_bstream_gunzip(apk_bstream_from_url(ictx->index), 1)); + bs = apk_bstream_from_istream(apk_bstream_gunzip(apk_bstream_from_url(ictx->index))); if (bs == NULL) return -1; r = apk_db_index_read(db, bs, 0); @@ -479,7 +479,7 @@ int apk_file_get_info(const char *filename, int checksum, struct apk_file_info * struct apk_istream *apk_istream_from_file_gz(const char *file) { - return apk_bstream_gunzip(apk_bstream_from_file(file), TRUE); + return apk_bstream_gunzip(apk_bstream_from_file(file)); } struct apk_fd_ostream { diff --git a/src/package.c b/src/package.c index 86595c916c..c01a5e8baa 100644 --- a/src/package.c +++ b/src/package.c @@ -430,12 +430,15 @@ static int apk_pkg_gzip_part(void *ctx, EVP_MD_CTX *mdctx, int part) struct apk_package *apk_pkg_read(struct apk_database *db, const char *file) { struct read_info_ctx ctx; + struct apk_file_info fi; struct apk_bstream *bs; struct apk_istream *tar; char realfile[PATH_MAX]; if (realpath(file, realfile) < 0) return NULL; + if (apk_file_get_info(realfile, APK_CHECKSUM_NONE, &fi) < 0) + return NULL; ctx.pkg = apk_pkg_new(); if (ctx.pkg == NULL) @@ -447,14 +450,15 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file) ctx.db = db; ctx.has_install = 0; + ctx.pkg->size = fi.size; - tar = apk_bstream_gunzip_mpart(bs, FALSE, apk_pkg_gzip_part, &ctx); + tar = apk_bstream_gunzip_mpart(bs, apk_pkg_gzip_part, &ctx); if (apk_parse_tar(tar, read_info_entry, &ctx) < 0) { apk_error("File %s is not an APK archive", file); bs->close(bs, NULL); goto err; } - bs->close(bs, &ctx.pkg->size); + tar->close(tar); if (ctx.pkg->name == NULL) { apk_error("File %s is corrupted", file); @@ -4,7 +4,7 @@ * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi> * All rights reserved. * - * This program is free software; you can redistribute it and/or modify it + * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. See http://www.gnu.org/ for details. */ @@ -68,7 +68,7 @@ struct apk_istream *apk_istream_from_url(const char *url) struct apk_istream *apk_istream_from_url_gz(const char *file) { - return apk_bstream_gunzip(apk_bstream_from_url(file), TRUE); + return apk_bstream_gunzip(apk_bstream_from_url(file)); } struct apk_bstream *apk_bstream_from_url(const char *url) |