index, version: support for repository descriptions (fixes #141)

ability embed description information to repository indexes
(e.g. repository name and version) and show it via "apk version -I".
cute-signatures
Timo Teras 2009-09-03 14:56:24 +04:00
parent 7829f1191f
commit 58e771303c
8 changed files with 89 additions and 25 deletions

View File

@ -24,7 +24,7 @@ int apk_tar_parse(struct apk_istream *,
apk_archive_entry_parser parser, void *ctx, apk_archive_entry_parser parser, void *ctx,
int soft_checksums); int soft_checksums);
int apk_tar_write_entry(struct apk_ostream *, const struct apk_file_info *ae, int apk_tar_write_entry(struct apk_ostream *, const struct apk_file_info *ae,
char *data); const char *data);
int apk_tar_write_padding(struct apk_ostream *, const struct apk_file_info *ae); int apk_tar_write_padding(struct apk_ostream *, const struct apk_file_info *ae);
int apk_archive_entry_extract(int atfd, const struct apk_file_info *ae, int apk_archive_entry_extract(int atfd, const struct apk_file_info *ae,

View File

@ -80,6 +80,8 @@ struct apk_name {
struct apk_repository { struct apk_repository {
char *url; char *url;
struct apk_checksum csum; struct apk_checksum csum;
apk_blob_t description;
}; };
struct apk_repository_list { struct apk_repository_list {

View File

@ -262,7 +262,8 @@ err:
return r; return r;
} }
int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae, char *data) int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae,
const char *data)
{ {
struct tar_header buf; struct tar_header buf;

View File

@ -1399,17 +1399,21 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi,
{ {
struct apkindex_ctx *ctx = (struct apkindex_ctx *) sctx; struct apkindex_ctx *ctx = (struct apkindex_ctx *) sctx;
struct apk_bstream *bs; struct apk_bstream *bs;
struct apk_repository *repo;
if (apk_sign_ctx_process_file(&ctx->sctx, fi, is) == 0) if (apk_sign_ctx_process_file(&ctx->sctx, fi, is) == 0)
return 0; return 0;
if (strcmp(fi->name, "APKINDEX") != 0) repo = &ctx->db->repos[ctx->repo];
return 0;
ctx->found = 1; if (strcmp(fi->name, "DESCRIPTION") == 0) {
bs = apk_bstream_from_istream(is); repo->description = apk_blob_from_istream(is, fi->size);
apk_db_index_read(ctx->db, bs, ctx->repo); } else if (strcmp(fi->name, "APKINDEX") == 0) {
bs->close(bs, NULL); ctx->found = 1;
bs = apk_bstream_from_istream(is);
apk_db_index_read(ctx->db, bs, ctx->repo);
bs->close(bs, NULL);
}
return 0; return 0;
} }

View File

@ -25,6 +25,7 @@ struct counts {
struct index_ctx { struct index_ctx {
const char *index; const char *index;
const char *output; const char *output;
const char *description;
time_t index_mtime; time_t index_mtime;
int method; int method;
}; };
@ -41,6 +42,9 @@ static int index_parse(void *ctx, struct apk_db_options *dbopts,
case 'o': case 'o':
ictx->output = optarg; ictx->output = optarg;
break; break;
case 'd':
ictx->description = optarg;
break;
case INDEX_OLD_FORMAT: case INDEX_OLD_FORMAT:
ictx->method = APK_SIGN_GENERATE_V1; ictx->method = APK_SIGN_GENERATE_V1;
break; break;
@ -159,27 +163,35 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
} }
} }
if (ictx->method == APK_SIGN_GENERATE) {
memset(&fi, 0, sizeof(fi));
fi.name = "APKINDEX";
fi.mode = 0644 | S_IFREG;
os = apk_ostream_counter(&fi.size);
apk_db_index_write(db, os);
os->close(os);
}
if (ictx->output != NULL) if (ictx->output != NULL)
os = apk_ostream_to_file(AT_FDCWD, ictx->output, NULL, 0644); os = apk_ostream_to_file(AT_FDCWD, ictx->output, NULL, 0644);
else else
os = apk_ostream_to_fd(STDOUT_FILENO); os = apk_ostream_to_fd(STDOUT_FILENO);
if (ictx->method == APK_SIGN_GENERATE) { if (ictx->method == APK_SIGN_GENERATE) {
struct apk_ostream *counter;
os = apk_ostream_gzip(os); os = apk_ostream_gzip(os);
memset(&fi, 0, sizeof(fi));
fi.mode = 0644 | S_IFREG;
fi.name = "DESCRIPTION";
fi.size = strlen(ictx->description);
apk_tar_write_entry(os, &fi, ictx->description);
memset(&fi, 0, sizeof(fi));
fi.mode = 0644 | S_IFREG;
fi.name = "APKINDEX";
counter = apk_ostream_counter(&fi.size);
apk_db_index_write(db, counter);
counter->close(counter);
apk_tar_write_entry(os, &fi, NULL); apk_tar_write_entry(os, &fi, NULL);
} total = apk_db_index_write(db, os);
total = apk_db_index_write(db, os);
if (ictx->method == APK_SIGN_GENERATE) {
apk_tar_write_padding(os, &fi); apk_tar_write_padding(os, &fi);
apk_tar_write_entry(os, NULL, NULL); apk_tar_write_entry(os, NULL, NULL);
} else {
total = apk_db_index_write(db, os);
} }
os->close(os); os->close(os);
@ -201,6 +213,9 @@ static struct apk_option index_options[] = {
{ 'x', "index", "Read INDEX to speed up new index creation by reusing " { 'x', "index", "Read INDEX to speed up new index creation by reusing "
"the information from an old index", "the information from an old index",
required_argument, "INDEX" }, required_argument, "INDEX" },
{ 'd', "description", "Embed TEXT as description and version "
"information of the repository index",
required_argument, "TEXT" },
{ INDEX_OLD_FORMAT, "old-format", { INDEX_OLD_FORMAT, "old-format",
"Specify to create old style index files" } "Specify to create old style index files" }
}; };

View File

@ -361,7 +361,7 @@ static struct apk_option info_options[] = {
static struct apk_applet apk_info = { static struct apk_applet apk_info = {
.name = "info", .name = "info",
.help = "Give detailed information about PACKAGEs.", .help = "Give detailed information about PACKAGEs or repositores.",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ, .open_flags = APK_OPENF_READ,
.context_size = sizeof(struct info_ctx), .context_size = sizeof(struct info_ctx),

View File

@ -17,6 +17,24 @@
static int update_main(void *ctx, struct apk_database *db, int argc, char **argv) static int update_main(void *ctx, struct apk_database *db, int argc, char **argv)
{ {
struct apk_repository *repo;
int i;
if (apk_verbosity < 1)
return 0;
for (i = 0; i < db->num_repos; i++) {
repo = &db->repos[i];
if (APK_BLOB_IS_NULL(repo->description))
continue;
apk_message("%.*s [%s]",
repo->description.len,
repo->description.ptr,
db->repos[i].url);
}
return 0; return 0;
} }

View File

@ -16,11 +16,31 @@
#include "apk_version.h" #include "apk_version.h"
struct ver_ctx { struct ver_ctx {
int (*action)(int argc, char **argv); int (*action)(struct apk_database *db, int argc, char **argv);
const char *limchars; const char *limchars;
}; };
static int ver_test(int argc, char **argv) static int ver_indexes(struct apk_database *db, int argc, char **argv)
{
struct apk_repository *repo;
int i;
for (i = 0; i < db->num_repos; i++) {
repo = &db->repos[i];
if (APK_BLOB_IS_NULL(repo->description))
continue;
apk_message("%.*s [%s]",
repo->description.len,
repo->description.ptr,
db->repos[i].url);
}
return 0;
}
static int ver_test(struct apk_database *db, int argc, char **argv)
{ {
int r; int r;
@ -32,7 +52,7 @@ static int ver_test(int argc, char **argv)
return 0; return 0;
} }
static int ver_validate(int argc, char **argv) static int ver_validate(struct apk_database *db, int argc, char **argv)
{ {
int i, r = 0; int i, r = 0;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
@ -50,6 +70,9 @@ static int ver_parse(void *ctx, struct apk_db_options *dbopts,
{ {
struct ver_ctx *ictx = (struct ver_ctx *) ctx; struct ver_ctx *ictx = (struct ver_ctx *) ctx;
switch (opt) { switch (opt) {
case 'I':
ictx->action = ver_indexes;
break;
case 't': case 't':
ictx->action = ver_test; ictx->action = ver_test;
break; break;
@ -99,7 +122,7 @@ static int ver_main(void *ctx, struct apk_database *db, int argc, char **argv)
if (ictx->action != NULL) if (ictx->action != NULL)
return ictx->action(argc, argv); return ictx->action(db, argc, argv);
if (apk_verbosity > 0) if (apk_verbosity > 0)
printf("%-42sAvailable:\n", "Installed:"); printf("%-42sAvailable:\n", "Installed:");
@ -131,6 +154,7 @@ ver_exit:
} }
static struct apk_option ver_options[] = { static struct apk_option ver_options[] = {
{ 'I', "indexes", "Print description and versions of indexes" },
{ 't', "test", "Compare two given versions" }, { 't', "test", "Compare two given versions" },
{ 'c', "check", "Check if the given version string is valid" }, { 'c', "check", "Check if the given version string is valid" },
{ 'l', "limit", "Limit output to packages whos status matches LIMCHAR", { 'l', "limit", "Limit output to packages whos status matches LIMCHAR",