From 6b471bb614beaeadcfa08008918ef6a2d93ac7e0 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Thu, 16 Jul 2009 15:16:05 +0300 Subject: various: new style index generation change the index generation to do old index, or the new style index where package identity is sha1 of control block and it's contained within an .tar.gz to allow signing in future. --- src/index.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'src/index.c') diff --git a/src/index.c b/src/index.c index d7402f9..86c1f44 100644 --- a/src/index.c +++ b/src/index.c @@ -10,18 +10,23 @@ */ #include +#include #include #include "apk_applet.h" #include "apk_database.h" +#define INDEX_OLD_FORMAT 0x10000 + struct counts { int unsatisfied; }; struct index_ctx { const char *index; + const char *output; time_t index_mtime; + int method; }; static int index_parse(void *ctx, int optch, int optindex, const char *optarg) @@ -32,6 +37,12 @@ static int index_parse(void *ctx, int optch, int optindex, const char *optarg) case 'x': ictx->index = optarg; break; + case 'o': + ictx->output = optarg; + break; + case INDEX_OLD_FORMAT: + ictx->method = APK_SIGN_GENERATE_V1; + break; default: return -1; } @@ -83,6 +94,16 @@ static int index_main(void *ctx, int argc, char **argv) int total, i, j, found, newpkgs = 0; struct index_ctx *ictx = (struct index_ctx *) ctx; + if (isatty(STDOUT_FILENO) && ictx->output == NULL && + !(apk_flags & APK_FORCE)) { + apk_error("Will not write binary index to console " + "without --force"); + return -1; + } + + if (ictx->method == 0) + ictx->method = APK_SIGN_GENERATE; + apk_db_open(&db, NULL, APK_OPENF_READ); if (index_read_file(&db, ictx) < 0) { apk_db_close(&db); @@ -137,13 +158,33 @@ static int index_main(void *ctx, int argc, char **argv) } while (0); if (!found) { - apk_db_pkg_add_file(&db, argv[i]); - newpkgs++; + if (apk_pkg_read(&db, argv[i], ictx->method) != NULL) + newpkgs++; } } - os = apk_ostream_to_fd(STDOUT_FILENO); + if (ictx->method == APK_SIGN_GENERATE) { + memset(&fi, 0, sizeof(fi)); + fi.name = "APKINDEX"; + fi.mode = 0755 | S_IFREG; + os = apk_ostream_counter(&fi.size); + apk_db_index_write(&db, os); + os->close(os); + } + + if (ictx->output != NULL) + os = apk_ostream_to_file(ictx->output, 0755); + else + os = apk_ostream_to_fd(STDOUT_FILENO); + if (ictx->method == APK_SIGN_GENERATE) { + os = apk_ostream_gzip(os); + apk_tar_write_entry(os, &fi, NULL); + } total = apk_db_index_write(&db, os); + if (ictx->method == APK_SIGN_GENERATE) { + apk_tar_write_padding(os, &fi); + apk_tar_write_entry(os, NULL, NULL); + } os->close(os); apk_hash_foreach(&db.available.names, warn_if_no_providers, &counts); @@ -160,9 +201,13 @@ static int index_main(void *ctx, int argc, char **argv) } static struct apk_option index_options[] = { + { 'o', "output", "Write the generated index to FILE", + required_argument, "FILE" }, { 'x', "index", "Read INDEX to speed up new index creation by reusing " "the information from an old index", required_argument, "INDEX" }, + { INDEX_OLD_FORMAT, "old-format", + "Specify to create old style index files" } }; static struct apk_applet apk_index = { -- cgit v1.2.3-60-g2f50