diff options
author | Timo Teräs <timo.teras@iki.fi> | 2013-06-18 14:53:59 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2013-06-18 14:54:18 +0300 |
commit | 5725f656b01c734580dd9d866a2855a9c333a441 (patch) | |
tree | 255253ee880072bf8906499786912d3d45f078fb /src | |
parent | 98c6b46de6d5074235e80617fd03c9e15cdd16e2 (diff) | |
download | apk-tools-5725f656b01c734580dd9d866a2855a9c333a441.tar.gz apk-tools-5725f656b01c734580dd9d866a2855a9c333a441.tar.bz2 apk-tools-5725f656b01c734580dd9d866a2855a9c333a441.tar.xz apk-tools-5725f656b01c734580dd9d866a2855a9c333a441.zip |
policy: new applet
to show different versions of package and the repositories from
which it is available from.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/apk_database.h | 2 | ||||
-rw-r--r-- | src/database.c | 8 | ||||
-rw-r--r-- | src/policy.c | 77 |
4 files changed, 83 insertions, 6 deletions
diff --git a/src/Makefile b/src/Makefile index 84653fc..bd58fd1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,7 +21,7 @@ endif progs-y += apk apk-objs := apk.o add.o del.o fix.o update.o info.o \ search.o upgrade.o cache.o ver.o index.o fetch.o \ - audit.o verify.o dot.o + audit.o verify.o dot.o policy.o libapk.so-objs := common.o database.o package.o archive.o \ version.o io.o url.o gunzip.o blob.o hash.o print.o \ diff --git a/src/apk_database.h b/src/apk_database.h index f3f7b7b..3d557bd 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -97,7 +97,7 @@ struct apk_name { }; struct apk_repository { - char *url; + const char *url; struct apk_checksum csum; apk_blob_t description; }; diff --git a/src/database.c b/src/database.c index 23da6af..72e568d 100644 --- a/src/database.c +++ b/src/database.c @@ -68,7 +68,7 @@ static const char * const apk_triggers_file = "lib/apk/db/triggers"; static const char * const apk_triggers_file_tmp = "lib/apk/db/triggers.new"; static const char * const apk_triggers_file_old = "var/lib/apk/triggers"; -static const char * const apk_installed_file = "lib/apk/db/installed"; +const char * const apk_installed_file = "lib/apk/db/installed"; static const char * const apk_installed_file_tmp = "lib/apk/db/installed.new"; static const char * const apk_installed_file_old = "var/lib/apk/installed"; @@ -609,7 +609,7 @@ int apk_repo_format_real_url(struct apk_database *db, struct apk_repository *rep int apk_repo_format_item(struct apk_database *db, struct apk_repository *repo, struct apk_package *pkg, int *fd, char *buf, size_t len) { - if (strcmp(repo->url, "cache") == 0) { + if (repo->url == apk_linked_cache_dir) { *fd = db->cache_fd; return apk_pkg_format_cache_pkg(APK_BLOB_PTR_LEN(buf, len), pkg); } else { @@ -1423,7 +1423,7 @@ static int add_repos_from_file(void *ctx, int dirfd, const char *file) static void apk_db_setup_repositories(struct apk_database *db) { db->repos[APK_REPOSITORY_CACHED] = (struct apk_repository) { - .url = "cache", + .url = apk_linked_cache_dir, .csum.data = { 0xb0,0x35,0x92,0x80,0x6e,0xfa,0xbf,0xee,0xb7,0x09, 0xf5,0xa7,0x0a,0x7c,0x17,0x26,0x69,0xb0,0x05,0x38 }, @@ -1737,7 +1737,7 @@ void apk_db_close(struct apk_database *db) } for (i = APK_REPOSITORY_FIRST_CONFIGURED; i < db->num_repos; i++) { - free(db->repos[i].url); + free((void*) db->repos[i].url); free(db->repos[i].description.ptr); } foreach_array_item(ppath, db->protected_paths) diff --git a/src/policy.c b/src/policy.c new file mode 100644 index 0000000..d3f171b --- /dev/null +++ b/src/policy.c @@ -0,0 +1,77 @@ +/* policy.c - Alpine Package Keeper (APK) + * + * Copyright (C) 2013 Timo Teräs <timo.teras@iki.fi> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include <stdio.h> +#include "apk_defines.h" +#include "apk_applet.h" +#include "apk_database.h" +#include "apk_version.h" +#include "apk_print.h" + +extern const char * const apk_installed_file; + +static void print_policy(struct apk_database *db, const char *match, struct apk_name *name, void *ctx) +{ + struct apk_provider *p; + struct apk_repository *repo; + int i, j, num = 0; +/* +zlib1g policy: + 2.0: + @testing http://nl.alpinelinux.org/alpine/edge/testing + 1.7: + @edge http://nl.alpinelinux.org/alpine/edge/main + 1.2.3.5 (upgradeable): + http://nl.alpinelinux.org/alpine/v2.6/main + 1.2.3.4 (installed): + /media/cdrom/... + http://nl.alpinelinux.org/alpine/v2.5/main + 1.1: + http://nl.alpinelinux.org/alpine/v2.4/main +*/ + foreach_array_item(p, name->providers) { + if (p->pkg->name != name) + continue; + if (num++ == 0) + printf("%s policy:\n", name->name); + printf(" " BLOB_FMT ":\n", BLOB_PRINTF(*p->version)); + if (p->pkg->ipkg != NULL) + printf(" %s\n", apk_installed_file); + for (i = 0; i < db->num_repos; i++) { + repo = &db->repos[i]; + if (!(BIT(i) & p->pkg->repos)) + continue; + for (j = 0; j < db->num_repo_tags; j++) { + if (db->repo_tags[j].allowed_repos & p->pkg->repos) + printf(" "BLOB_FMT"%s%s\n", + BLOB_PRINTF(db->repo_tags[j].tag), + j == 0 ? "" : " ", + repo->url); + } + } + } +} + +static int policy_main(void *ctx, struct apk_database *db, struct apk_string_array *args) +{ + apk_name_foreach_matching(db, args, apk_foreach_genid(), print_policy, NULL); + return 0; +} + +static struct apk_applet apk_policy = { + .name = "policy", + .help = "Show repository policy for packages.", + .open_flags = APK_OPENF_READ, + .main = policy_main, +}; + +APK_DEFINE_APPLET(apk_policy); + + |