From 2b24128059bdf3b0207932068e64ef3bd161d983 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 16 Feb 2009 16:24:33 +0100 Subject: [PATCH] xbps-bin: added support for the show target. --HG-- extra : convert_revision : 24b2d30a94c95b22b1c524203cf578da03314335 --- bin/xbps-bin/Makefile | 3 ++- bin/xbps-bin/main.c | 11 +++++++++++ bin/xbps-repo/util.c | 35 +++++++++++++++++++++++++++++++++++ bin/xbps-repo/util.h | 12 +++++++++--- doc/TODO | 1 - include/xbps_api.h | 3 +++ 6 files changed, 60 insertions(+), 5 deletions(-) diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile index aa1a060fc2c..c942ce52440 100644 --- a/bin/xbps-bin/Makefile +++ b/bin/xbps-bin/Makefile @@ -1,7 +1,7 @@ TOPDIR = ../.. include $(TOPDIR)/vars.mk -OBJS = main.o +OBJS = main.o ../xbps-repo/util.o BIN = xbps-bin all: $(BIN) @@ -18,6 +18,7 @@ clean-bins: clean-objs: -rm -f *.o + -rm -f ../xbps-repo/util.o install: $(BIN) install -d $(SBINDIR) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index fb00fb4e668..314801998f1 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -33,6 +33,7 @@ #include #include +#include "../xbps-repo/util.h" static void usage(void); static void show_missing_deps(prop_dictionary_t, const char *); @@ -188,6 +189,16 @@ main(int argc, char **argv) printf("Package %s removed successfully.\n", argv[1]); } + } else if (strcasecmp(argv[0], "show") == 0) { + /* Shows info about an installed binary package. */ + if (argc != 2) + usage(); + + rv = show_pkg_info_from_metadir(argv[1]); + if (rv != 0) { + printf("Package %s not installed\n", argv[1]); + exit(EXIT_FAILURE); + } } else { usage(); } diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index be7a56a6839..a24fb9c01ab 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -152,6 +152,41 @@ search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done) return 0; } +int +show_pkg_info_from_metadir(const char *pkgname) +{ + prop_dictionary_t pkgd; + size_t len = 0; + char *plist, *path; + + /* XBPS_META_PATH/metadata/ + NULL */ + len = strlen(XBPS_META_PATH) + strlen(pkgname) + 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_PKGPROPS); + if (plist == NULL) { + free(path); + return EINVAL; + } + free(path); + + pkgd = prop_dictionary_internalize_from_file(plist); + if (pkgd == NULL) { + free(plist); + return errno; + } + + show_pkg_info(pkgd); + prop_object_release(pkgd); + free(plist); + + 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 eaac833934b..943d4d4414a 100644 --- a/bin/xbps-repo/util.h +++ b/bin/xbps-repo/util.h @@ -23,6 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -int search_string_in_pkgs(prop_object_t, void *, bool *); -int show_pkg_info_from_repolist(prop_object_t, void *, bool *); -int list_strings_in_array(prop_object_t, void *, bool *); +#ifndef _XBPS_REPO_UTIL_H_ +#define _XBPS_REPO_UTIL_H_ + +int search_string_in_pkgs(prop_object_t, void *, bool *); +int show_pkg_info_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 *); + +#endif /* !_XBPS_REPO_UTIL_H_ */ diff --git a/doc/TODO b/doc/TODO index 5b67873b49d..eb9cf0af8ef 100644 --- a/doc/TODO +++ b/doc/TODO @@ -25,7 +25,6 @@ xbps-bin: * Add support to detect orphaned packages. * Add support to check sha256 hashes of all installed files, as well as hashes for binary packages before installation happens. - * Add support to use the show target with no repositories. * Add support to install binary packages without any repository. xbps-repo: diff --git a/include/xbps_api.h b/include/xbps_api.h index a4c16f29ec3..6c6095d8711 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -47,6 +47,9 @@ /* Filename of the packages register. */ #define XBPS_REGPKGDB "regpkgdb.plist" +/* Filename of the package properties plist file. */ +#define XBPS_PKGPROPS "props.plist" + #include "cmpver.h" #include "fexec.h" #include "humanize_number.h"