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,
int soft_checksums);
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_archive_entry_extract(int atfd, const struct apk_file_info *ae,

View File

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

View File

@ -262,7 +262,8 @@ err:
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;

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 apk_bstream *bs;
struct apk_repository *repo;
if (apk_sign_ctx_process_file(&ctx->sctx, fi, is) == 0)
return 0;
if (strcmp(fi->name, "APKINDEX") != 0)
return 0;
repo = &ctx->db->repos[ctx->repo];
ctx->found = 1;
bs = apk_bstream_from_istream(is);
apk_db_index_read(ctx->db, bs, ctx->repo);
bs->close(bs, NULL);
if (strcmp(fi->name, "DESCRIPTION") == 0) {
repo->description = apk_blob_from_istream(is, fi->size);
} else if (strcmp(fi->name, "APKINDEX") == 0) {
ctx->found = 1;
bs = apk_bstream_from_istream(is);
apk_db_index_read(ctx->db, bs, ctx->repo);
bs->close(bs, NULL);
}
return 0;
}

View File

@ -25,6 +25,7 @@ struct counts {
struct index_ctx {
const char *index;
const char *output;
const char *description;
time_t index_mtime;
int method;
};
@ -41,6 +42,9 @@ static int index_parse(void *ctx, struct apk_db_options *dbopts,
case 'o':
ictx->output = optarg;
break;
case 'd':
ictx->description = optarg;
break;
case INDEX_OLD_FORMAT:
ictx->method = APK_SIGN_GENERATE_V1;
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)
os = apk_ostream_to_file(AT_FDCWD, ictx->output, NULL, 0644);
else
os = apk_ostream_to_fd(STDOUT_FILENO);
if (ictx->method == APK_SIGN_GENERATE) {
struct apk_ostream *counter;
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);
}
total = apk_db_index_write(db, os);
if (ictx->method == APK_SIGN_GENERATE) {
total = apk_db_index_write(db, os);
apk_tar_write_padding(os, &fi);
apk_tar_write_entry(os, NULL, NULL);
} else {
total = apk_db_index_write(db, 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 "
"the information from an old 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",
"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 = {
.name = "info",
.help = "Give detailed information about PACKAGEs.",
.help = "Give detailed information about PACKAGEs or repositores.",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ,
.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)
{
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;
}

View File

@ -16,11 +16,31 @@
#include "apk_version.h"
struct ver_ctx {
int (*action)(int argc, char **argv);
int (*action)(struct apk_database *db, int argc, char **argv);
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;
@ -32,7 +52,7 @@ static int ver_test(int argc, char **argv)
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;
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;
switch (opt) {
case 'I':
ictx->action = ver_indexes;
break;
case 't':
ictx->action = ver_test;
break;
@ -99,7 +122,7 @@ static int ver_main(void *ctx, struct apk_database *db, int argc, char **argv)
if (ictx->action != NULL)
return ictx->action(argc, argv);
return ictx->action(db, argc, argv);
if (apk_verbosity > 0)
printf("%-42sAvailable:\n", "Installed:");
@ -131,6 +154,7 @@ ver_exit:
}
static struct apk_option ver_options[] = {
{ 'I', "indexes", "Print description and versions of indexes" },
{ 't', "test", "Compare two given versions" },
{ 'c', "check", "Check if the given version string is valid" },
{ 'l', "limit", "Limit output to packages whos status matches LIMCHAR",