From 32597d85c1bb2c8c9c3c64b3cb7695dace773daa Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 22 Dec 2011 14:41:40 +0100 Subject: [PATCH] Use xbps_regpkgdb_foreach_pkg_cb() where needed. --- bin/xbps-bin/main.c | 17 +++++++---------- bin/xbps-bin/util.c | 8 ++++++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 264c64d5..f99c72d5 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -190,11 +190,6 @@ main(int argc, char **argv) if (argc < 1 || argc > 2) usage(xhp); - if (xhp->regpkgdb_dictionary == NULL) { - printf("No packages currently installed.\n"); - goto out; - } - lpc.check_state = true; lpc.state = 0; if (argv[1]) { @@ -219,9 +214,12 @@ main(int argc, char **argv) /* * Find the longest pkgver string to pretty print the output. */ - lpc.pkgver_len = find_longest_pkgver(xhp->regpkgdb_dictionary); - rv = xbps_callback_array_iter_in_dict(xhp->regpkgdb_dictionary, - "packages", list_pkgs_in_dict, &lpc); + lpc.pkgver_len = find_longest_pkgver(NULL); + rv = xbps_regpkgdb_foreach_pkg_cb(list_pkgs_in_dict, &lpc); + if (rv == ENOENT) { + printf("No packages currently registered.\n"); + rv = 0; + } } else if (strcasecmp(argv[0], "install") == 0) { /* Installs a binary package and required deps. */ @@ -368,8 +366,7 @@ main(int argc, char **argv) if (argc != 1) usage(xhp); - rv = xbps_callback_array_iter_in_dict(xhp->regpkgdb_dictionary, - "packages", list_manual_pkgs, NULL); + rv = xbps_regpkgdb_foreach_pkg_cb(list_manual_pkgs, NULL); } else if (strcasecmp(argv[0], "show-revdeps") == 0) { /* diff --git a/bin/xbps-bin/util.c b/bin/xbps-bin/util.c index aba79ee9..6829caf5 100644 --- a/bin/xbps-bin/util.c +++ b/bin/xbps-bin/util.c @@ -190,8 +190,12 @@ find_longest_pkgver(prop_dictionary_t d) { size_t len = 0; - (void)xbps_callback_array_iter_in_dict(d, "packages", - _find_longest_pkgver_cb, &len); + if (prop_object_type(d) == PROP_TYPE_DICTIONARY) + (void)xbps_callback_array_iter_in_dict(d, "packages", + _find_longest_pkgver_cb, &len); + else + (void)xbps_regpkgdb_foreach_pkg_cb( + _find_longest_pkgver_cb, &len); return len; }