summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-09-03 14:56:24 +0400
committerTimo Teras <timo.teras@iki.fi>2009-09-03 14:56:24 +0400
commit58e771303c95f9d97d009602516b509866c3fb5a (patch)
tree9cf8ce0d4608d4531850177549cb70670544fbb4
parent7829f1191f1812f30c763a685dff1b61393f7491 (diff)
downloadapk-tools-58e771303c95f9d97d009602516b509866c3fb5a.tar.gz
apk-tools-58e771303c95f9d97d009602516b509866c3fb5a.tar.bz2
apk-tools-58e771303c95f9d97d009602516b509866c3fb5a.tar.xz
apk-tools-58e771303c95f9d97d009602516b509866c3fb5a.zip
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".
-rw-r--r--src/apk_archive.h2
-rw-r--r--src/apk_database.h2
-rw-r--r--src/archive.c3
-rw-r--r--src/database.c16
-rw-r--r--src/index.c39
-rw-r--r--src/info.c2
-rw-r--r--src/update.c18
-rw-r--r--src/ver.c32
8 files changed, 89 insertions, 25 deletions
diff --git a/src/apk_archive.h b/src/apk_archive.h
index f983203..f1b5aaf 100644
--- a/src/apk_archive.h
+++ b/src/apk_archive.h
@@ -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,
diff --git a/src/apk_database.h b/src/apk_database.h
index c49eba8..8ec7bac 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -80,6 +80,8 @@ struct apk_name {
struct apk_repository {
char *url;
struct apk_checksum csum;
+
+ apk_blob_t description;
};
struct apk_repository_list {
diff --git a/src/archive.c b/src/archive.c
index 8c1e798..58d2573 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -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;
diff --git a/src/database.c b/src/database.c
index 5673c3c..16f8bb8 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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;
}
diff --git a/src/index.c b/src/index.c
index d485afd..ac6a763 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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" }
};
diff --git a/src/info.c b/src/info.c
index bdc3a14..7ca486c 100644
--- a/src/info.c
+++ b/src/info.c
@@ -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),
diff --git a/src/update.c b/src/update.c
index eed5d45..b558342 100644
--- a/src/update.c
+++ b/src/update.c
@@ -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;
}
diff --git a/src/ver.c b/src/ver.c
index 5a8fb9c..3f85afc 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -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",