xbps-bin: implement 'files' target, to show installed files for a pkg.

--HG--
extra : convert_revision : c522253a61c23e8439c6de343e713497a2a10033
This commit is contained in:
Juan RP 2009-02-26 02:46:20 +01:00
parent f53e18171a
commit 8d243e8dab
4 changed files with 70 additions and 2 deletions

View file

@ -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<pkgname>\n"
" files\t<pkgname>\n"
" remove\t<pkgname>\n"
" show\t<pkgname>\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 {

View file

@ -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/<pkgname>/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)
{

View file

@ -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 *);

View file

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