From 210f2799fce0221d8405cad7e427f46ba3d95caf Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 27 Oct 2010 13:10:03 +0200 Subject: [PATCH] xbps-bin(8): modify the 'list' target to accept an optional argument to list packages in the specified state, so that you can list packages that need to be purged, configured and broken (will be used in the future). --- NEWS | 4 ++++ bin/xbps-bin/main.c | 45 ++++++++++++++++++++++++++++++++--------- bin/xbps-bin/xbps-bin.8 | 11 ++++++---- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 94b891da..f4e51a4e 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.6.2 (???): + * xbps-bin(8): modify the 'list' target to accept an optional argument to + list packages in the specified state, so that you can list packages that + need to be purged, configured and broken (will be used in the future). + * xbps-bin(8): added a new target 'find-files' to find which installed package(s) own a file. Exact matches "/bin/mount" or patterns "/usr/lib/libb[ao]b\*" can be specified. diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 69e29ce7..72ced70b 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -45,7 +45,7 @@ usage(void) " check\t\t[|]\n" " find-files\t\n" " install\t\t[|]\n" - " list\n" + " list\t\t[state]\n" " list-manual\n" " purge\t\t[|]\n" " reconfigure\t\t[|]\n" @@ -74,20 +74,27 @@ static int list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) { const char *pkgver, *short_desc; + pkg_state_t curstate, *wantstate = (pkg_state_t *)arg; - (void)arg; (void)loop_done; assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); - prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); - if (pkgver && short_desc) { - printf("%s\t%s\n", pkgver, short_desc); - return 0; + if (wantstate && *wantstate != 0) { + if (xbps_get_pkg_state_dictionary(obj, &curstate)) + return EINVAL; + + if (curstate != *wantstate) + return 0; } - return EINVAL; + prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); + prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); + if (!pkgver && !short_desc) + return EINVAL; + + printf("%s\t%s\n", pkgver, short_desc); + return 0; } static int @@ -120,6 +127,7 @@ int main(int argc, char **argv) { prop_dictionary_t dict; + pkg_state_t pkgstate = 0; struct sigaction sa; int i = 0, c, flags = 0, rv = 0; bool yes, purge; @@ -186,7 +194,7 @@ main(int argc, char **argv) if (strcasecmp(argv[0], "list") == 0) { /* Lists packages currently registered in database. */ - if (argc != 1) + if (argc < 1 || argc > 2) usage(); if (dict == NULL) { @@ -194,8 +202,25 @@ main(int argc, char **argv) goto out; } + if (argv[1]) { + if (strcmp(argv[1], "installed") == 0) + pkgstate = XBPS_PKG_STATE_INSTALLED; + else if (strcmp(argv[1], "unpacked") == 0) + pkgstate = XBPS_PKG_STATE_UNPACKED; + else if (strcmp(argv[1], "config-files") == 0) + pkgstate = XBPS_PKG_STATE_CONFIG_FILES; + else { + fprintf(stderr, + "E: invalid state `%s'. Accepted values: " + "config-files, unpacked, " + "installed [default]\n", argv[1]); + rv = -1; + goto out; + } + + } if (!xbps_callback_array_iter_in_dict(dict, "packages", - list_pkgs_in_dict, NULL)) { + list_pkgs_in_dict, &pkgstate)) { rv = errno; goto out; } diff --git a/bin/xbps-bin/xbps-bin.8 b/bin/xbps-bin/xbps-bin.8 index fb8d2109..13c62087 100644 --- a/bin/xbps-bin/xbps-bin.8 +++ b/bin/xbps-bin/xbps-bin.8 @@ -2,12 +2,12 @@ .\" Title: xbps-bin .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.75.2 -.\" Date: 26/10/2010 +.\" Date: 27/10/2010 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "XBPS\-BIN" "8" "26/10/2010" "\ \&" "\ \&" +.TH "XBPS\-BIN" "8" "27/10/2010" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -145,9 +145,12 @@ script and will change its state to in the package database\&. .RE .PP -\fBlist\fR +\fBlist [\fR\fB\fIstate\fR\fR] .RS 4 -Lists all currently installed packages\&. +Lists all currently installed packages\&. Optionally another argument can be specified to +list only packages with the specified \fIstate\fR. By default only packages that are fully +installed will be listed if no \fIstate\fR has been specified. Accepted states are: +\fBconfig\-files\fR, \fBunpacked\fR and \fBinstalled\fR. .RE .PP \fBlist\-manual\fR