From 8d243e8dabd520bd29c385cb54d7c5a57f814a2b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 26 Feb 2009 02:46:20 +0100 Subject: [PATCH] xbps-bin: implement 'files' target, to show installed files for a pkg. --HG-- extra : convert_revision : c522253a61c23e8439c6de343e713497a2a10033 --- bin/xbps-bin/main.c | 16 +++++++++++-- bin/xbps-repo/util.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ bin/xbps-repo/util.h | 1 + include/xbps_api.h | 1 + 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 0bd318460bd..bde83ff2d1c 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -45,9 +45,10 @@ usage(void) { printf("Usage: xbps-bin [options] [action] [arguments]\n\n" " Available actions:\n" - " install, list, remove, show\n" + " install, list, remove, show, files\n" " Actions with arguments:\n" " install\t\n" + " files\t\n" " remove\t\n" " show\t\n" " Options shared by all actions:\n" @@ -57,6 +58,7 @@ usage(void) " Examples:\n" " $ xbps-bin install klibc\n" " $ xbps-bin -r /path/to/root install klibc\n" + " $ xbps-bin files klibc\n" " $ xbps-bin list\n" " $ xbps-bin remove klibc\n" " $ xbps-bin show klibc\n"); @@ -207,7 +209,17 @@ main(int argc, char **argv) rv = show_pkg_info_from_metadir(argv[1]); if (rv != 0) { - printf("Package %s not installed\n", argv[1]); + printf("Package %s not installed.\n", argv[1]); + exit(EXIT_FAILURE); + } + } else if (strcasecmp(argv[0], "files") == 0) { + /* Shows files installed by a binary package. */ + if (argc != 2) + usage(); + + rv = show_pkg_files_from_metadir(argv[1]); + if (rv != 0) { + printf("Package %s not installed.\n", argv[1]); exit(EXIT_FAILURE); } } else { diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 15804934951..b62d8caf3bb 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -35,6 +35,7 @@ #include "util.h" static void show_pkg_info(prop_dictionary_t); +static int show_pkg_files(prop_object_t, void *, bool *); static int show_pkg_namedesc(prop_object_t, void *, bool *); static int list_strings_in_array2(prop_object_t, void *, bool *); @@ -192,6 +193,59 @@ show_pkg_info_from_metadir(const char *pkgname) return 0; } +int +show_pkg_files_from_metadir(const char *pkgname) +{ + prop_dictionary_t pkgd; + size_t len = 0; + char *plist, *path; + int rv = 0; + + /* XBPS_META_PATH/metadata//XBPS_PKGFILES + NULL */ + len = strlen(XBPS_META_PATH) + strlen(pkgname) + + strlen(XBPS_PKGFILES) + 12; + path = malloc(len); + if (path == NULL) + return EINVAL; + + (void)snprintf(path, len, "%s/metadata/%s", XBPS_META_PATH, pkgname); + + plist = xbps_append_full_path(true, path, XBPS_PKGFILES); + if (plist == NULL) { + free(path); + return EINVAL; + } + free(path); + + pkgd = prop_dictionary_internalize_from_file(plist); + if (pkgd == NULL) { + free(plist); + return errno; + } + + rv = xbps_callback_array_iter_in_dict(pkgd, "filelist", + show_pkg_files, NULL); + prop_object_release(pkgd); + free(plist); + + return rv; +} + +static int +show_pkg_files(prop_object_t obj, void *arg, bool *loop_done) +{ + const char *file = NULL; + + (void)arg; + (void)loop_done; + + prop_dictionary_get_cstring_nocopy(obj, "file", &file); + if (file != NULL) + printf("%s\n", file); + + return 0; +} + int show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done) { diff --git a/bin/xbps-repo/util.h b/bin/xbps-repo/util.h index 943d4d4414a..ed381399512 100644 --- a/bin/xbps-repo/util.h +++ b/bin/xbps-repo/util.h @@ -28,6 +28,7 @@ int search_string_in_pkgs(prop_object_t, void *, bool *); int show_pkg_info_from_metadir(const char *); +int show_pkg_files_from_metadir(const char *); int show_pkg_info_from_repolist(prop_object_t, void *, bool *); int list_strings_in_array(prop_object_t, void *, bool *); diff --git a/include/xbps_api.h b/include/xbps_api.h index 45baefd3d72..23b7e430127 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -49,6 +49,7 @@ /* Filename of the package properties plist file. */ #define XBPS_PKGPROPS "props.plist" +#define XBPS_PKGFILES "files.plist" /* Unpack flags */ #define XBPS_UNPACK_VERBOSE 0x00000001