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).
This commit is contained in:
Juan RP 2010-10-27 13:10:03 +02:00
parent ef7da88db1
commit 210f2799fc
3 changed files with 46 additions and 14 deletions

4
NEWS
View File

@ -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.

View File

@ -45,7 +45,7 @@ usage(void)
" check\t\t[<pkgname>|<all>]\n"
" find-files\t<pattern>\n"
" install\t\t[<pkgname(s)>|<pkgpattern(s)>]\n"
" list\n"
" list\t\t[state]\n"
" list-manual\n"
" purge\t\t[<pkgname>|<all>]\n"
" reconfigure\t\t[<pkgname>|<all>]\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;
}

View File

@ -2,12 +2,12 @@
.\" Title: xbps-bin
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" 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