summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-21 17:59:08 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-21 17:59:08 +0300
commit2345548e4522a988024426432d0ed0e421599eba (patch)
treeb648020137e6c69b539a2df171fc54c654b1b12f
parent812483515ad95c84de9c49de28fbd5ee769facfc (diff)
downloadapk-tools-2345548e4522a988024426432d0ed0e421599eba.tar.gz
apk-tools-2345548e4522a988024426432d0ed0e421599eba.tar.bz2
apk-tools-2345548e4522a988024426432d0ed0e421599eba.tar.xz
apk-tools-2345548e4522a988024426432d0ed0e421599eba.zip
index: read also new style index files
-rw-r--r--src/apk_database.h1
-rw-r--r--src/database.c59
-rw-r--r--src/index.c11
3 files changed, 42 insertions, 29 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index 4cf8b14..0edf4f2 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -140,6 +140,7 @@ struct apk_package *apk_db_get_pkg(struct apk_database *db, struct apk_checksum
struct apk_package *apk_db_get_file_owner(struct apk_database *db, apk_blob_t filename);
int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo);
+int apk_db_index_read_file(struct apk_database *db, const char *file, int repo);
int apk_db_index_write(struct apk_database *db, struct apk_ostream *os);
int apk_db_add_repository(apk_database_t db, apk_blob_t repository);
diff --git a/src/database.c b/src/database.c
index d5f83e6..b9eef79 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1152,6 +1152,40 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi,
return 0;
}
+static int load_index(struct apk_database *db, struct apk_bstream *bs,
+ int targz, int repo)
+{
+ if (targz) {
+ struct apk_istream *is;
+ struct apkindex_ctx ctx;
+
+ ctx.db = db;
+ ctx.repo = repo;
+ apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY, NULL);
+ is = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx);
+ apk_tar_parse(is, load_apkindex, &ctx);
+ is->close(is);
+ apk_sign_ctx_free(&ctx.sctx);
+ if (!ctx.sctx.data_verified)
+ return -1;
+ } else {
+ bs = apk_bstream_from_istream(apk_bstream_gunzip(bs));
+ apk_db_index_read(db, bs, repo);
+ bs->close(bs, NULL);
+ }
+ return 0;
+}
+
+int apk_db_index_read_file(struct apk_database *db, const char *file, int repo)
+{
+ int targz = 1;
+
+ if (strstr(file, ".tar.gz") == NULL && strstr(file, ".gz") != NULL)
+ targz = 0;
+
+ return load_index(db, apk_bstream_from_file(file), targz, repo);
+}
+
int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
{
struct apk_database *db = _db.db;
@@ -1195,28 +1229,11 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
apk_warning("Failed to open index for %s", repo->url);
return -1;
}
- if (targz) {
- struct apk_istream *is;
- struct apkindex_ctx ctx;
-
- ctx.db = db;
- ctx.repo = r;
- apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY, NULL);
- is = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx);
- r = apk_tar_parse(is, load_apkindex, &ctx);
- is->close(is);
- apk_sign_ctx_free(&ctx.sctx);
- if (!ctx.sctx.data_verified) {
- apk_error("Bad repository signature: %s", repo->url);
- return -1;
- }
- } else {
- bs = apk_bstream_from_istream(apk_bstream_gunzip(bs));
- apk_db_index_read(db, bs, r);
- bs->close(bs, NULL);
- }
- return 0;
+ r = load_index(db, bs, targz, r);
+ if (r != 0)
+ apk_error("%s: Bad repository signature", repo->url);
+ return r;
}
static void extract_cb(void *_ctx, size_t progress)
diff --git a/src/index.c b/src/index.c
index 2a7365e..608dea8 100644
--- a/src/index.c
+++ b/src/index.c
@@ -51,20 +51,15 @@ static int index_parse(void *ctx, int optch, int optindex, const char *optarg)
static int index_read_file(struct apk_database *db, struct index_ctx *ictx)
{
- struct apk_bstream *bs;
struct apk_file_info fi;
- int r;
+
if (ictx->index == NULL)
return 0;
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)));
- if (bs == NULL)
- return -1;
- r = apk_db_index_read(db, bs, 0);
- bs->close(bs, NULL);
- return r;
+
+ return apk_db_index_read_file(db, ictx->index, 0);
}
static int warn_if_no_providers(apk_hash_item item, void *ctx)