xbps-bin: implement full support for the 'show' target.
This will try to show the package information by looking in all repositories registered. The first one that has the package info wins. --HG-- extra : convert_revision : 33b93fd115a765d696af76ca20c1669ef277cd35
This commit is contained in:
parent
6698f3a1ff
commit
c3c632e387
4 changed files with 86 additions and 22 deletions
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#include "xbps_api.h"
|
#include "xbps_api.h"
|
||||||
|
|
||||||
static bool xbps_list_strings_in_array2(prop_object_t);
|
static bool xbps_list_strings_in_array2(prop_object_t, void *);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
|
xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
|
||||||
|
@ -66,7 +66,8 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
|
||||||
|
|
||||||
bool
|
bool
|
||||||
xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key,
|
xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key,
|
||||||
bool (*func)(prop_object_t))
|
bool (*func)(prop_object_t, void *),
|
||||||
|
void *arg)
|
||||||
{
|
{
|
||||||
prop_object_iterator_t iter;
|
prop_object_iterator_t iter;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
|
@ -79,7 +80,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while ((obj = prop_object_iterator_next(iter))) {
|
while ((obj = prop_object_iterator_next(iter))) {
|
||||||
if (!(*func)(obj)) {
|
if (!(*func)(obj, arg)) {
|
||||||
prop_object_iterator_release(iter);
|
prop_object_iterator_release(iter);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +258,7 @@ xbps_show_pkg_info(prop_dictionary_t dict)
|
||||||
printf("\n\t");
|
printf("\n\t");
|
||||||
if (!xbps_callback_array_iter_in_dict(dict,
|
if (!xbps_callback_array_iter_in_dict(dict,
|
||||||
prop_dictionary_keysym_cstring_nocopy(obj),
|
prop_dictionary_keysym_cstring_nocopy(obj),
|
||||||
xbps_list_strings_in_array2))
|
xbps_list_strings_in_array2, NULL))
|
||||||
return;
|
return;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
@ -267,7 +268,38 @@ xbps_show_pkg_info(prop_dictionary_t dict)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
xbps_list_pkgs_in_dict(prop_object_t obj)
|
xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg)
|
||||||
|
{
|
||||||
|
prop_dictionary_t dict, pkgdict;
|
||||||
|
prop_string_t oloc;
|
||||||
|
const char *repofile, *repoloc;
|
||||||
|
|
||||||
|
if (prop_object_type(obj) != PROP_TYPE_STRING)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
repofile = prop_string_cstring_nocopy(obj);
|
||||||
|
dict = prop_dictionary_internalize_from_file(repofile);
|
||||||
|
pkgdict = xbps_find_pkg_in_dict(dict, arg);
|
||||||
|
if (pkgdict == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
oloc = prop_dictionary_get(dict, "location-remote");
|
||||||
|
if (oloc == NULL)
|
||||||
|
oloc = prop_dictionary_get(dict, "location-local");
|
||||||
|
|
||||||
|
if (oloc && prop_object_type(oloc) == PROP_TYPE_STRING)
|
||||||
|
repoloc = prop_string_cstring_nocopy(oloc);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
printf("Repository: %s\n", repoloc);
|
||||||
|
xbps_show_pkg_info(pkgdict);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
xbps_list_pkgs_in_dict(prop_object_t obj, void *arg)
|
||||||
{
|
{
|
||||||
const char *pkgname, *version, *short_desc;
|
const char *pkgname, *version, *short_desc;
|
||||||
|
|
||||||
|
@ -286,7 +318,7 @@ xbps_list_pkgs_in_dict(prop_object_t obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
xbps_list_strings_in_array2(prop_object_t obj)
|
xbps_list_strings_in_array2(prop_object_t obj, void *arg)
|
||||||
{
|
{
|
||||||
static uint16_t count;
|
static uint16_t count;
|
||||||
|
|
||||||
|
@ -304,7 +336,7 @@ xbps_list_strings_in_array2(prop_object_t obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
xbps_list_strings_in_array(prop_object_t obj)
|
xbps_list_strings_in_array(prop_object_t obj, void *arg)
|
||||||
{
|
{
|
||||||
if (prop_object_type(obj) != PROP_TYPE_STRING)
|
if (prop_object_type(obj) != PROP_TYPE_STRING)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -58,13 +58,15 @@ xbps_add_obj_to_array(prop_array_t, prop_object_t);
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* - prop_dictionary_t: dictionary to search on.
|
* - prop_dictionary_t: dictionary to search on.
|
||||||
* - const char *: key of the array.
|
* - const char *: key of the array.
|
||||||
* - (*func)(prop_object_t): callback associated.
|
* - (*func)(prop_object_t, void *): callback associated.
|
||||||
|
* - void *: argument passed to the callback.
|
||||||
*
|
*
|
||||||
* Returns true on success, false otherwise and the loop is terminated.
|
* Returns true on success, false otherwise and the loop is terminated.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
xbps_callback_array_iter_in_dict(prop_dictionary_t, const char *,
|
xbps_callback_array_iter_in_dict(prop_dictionary_t, const char *,
|
||||||
bool (*func)(prop_object_t));
|
bool (*func)(prop_object_t, void *),
|
||||||
|
void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finds a package's dictionary into the main dictionary.
|
* Finds a package's dictionary into the main dictionary.
|
||||||
|
@ -108,22 +110,24 @@ xbps_get_array_iter_from_dict(prop_dictionary_t, const char *);
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* - prop_object_t: the object to be processed.
|
* - prop_object_t: the object to be processed.
|
||||||
|
* - void *: argument passed.
|
||||||
*
|
*
|
||||||
* Returns true on success, false otherwise.
|
* Returns true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
xbps_list_pkgs_in_dict(prop_object_t);
|
xbps_list_pkgs_in_dict(prop_object_t, void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lists all string values in an array object in a dictionary.
|
* Lists all string values in an array object in a dictionary.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* - prop_object_t: the object to be processed.
|
* - prop_object_t: the object to be processed.
|
||||||
|
* - void *: argument passed.
|
||||||
*
|
*
|
||||||
* Returns true on success, false otherwise.
|
* Returns true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
xbps_list_strings_in_array(prop_object_t);
|
xbps_list_strings_in_array(prop_object_t, void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Registers a repository specified by an URI into the pool.
|
* Registers a repository specified by an URI into the pool.
|
||||||
|
@ -146,4 +150,18 @@ xbps_register_repository(const char *);
|
||||||
void
|
void
|
||||||
xbps_show_pkg_info(prop_dictionary_t);
|
xbps_show_pkg_info(prop_dictionary_t);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shows information of a package by searching in all repositories
|
||||||
|
* registered in the pool. It will show information from the
|
||||||
|
* first repository that has the package.
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* - prop_object_t: the object to be processed.
|
||||||
|
* - const char *: passed argument (pkgname string).
|
||||||
|
*
|
||||||
|
* Returns true on success, false otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg);
|
||||||
|
|
||||||
#endif /* !_XBPS_PLIST_H_ */
|
#endif /* !_XBPS_PLIST_H_ */
|
||||||
|
|
|
@ -39,6 +39,7 @@ typedef struct repository_info {
|
||||||
size_t total_pkgs;
|
size_t total_pkgs;
|
||||||
} repo_info_t;
|
} repo_info_t;
|
||||||
|
|
||||||
|
static prop_dictionary_t getrepolist_dict(void);
|
||||||
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
|
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
|
@ -90,6 +91,21 @@ pkgindex_getinfo(prop_dictionary_t dict, repo_info_t *ri)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static prop_dictionary_t
|
||||||
|
getrepolist_dict(void)
|
||||||
|
{
|
||||||
|
prop_dictionary_t dict;
|
||||||
|
|
||||||
|
dict = prop_dictionary_internalize_from_file(XBPS_REPOLIST_PATH);
|
||||||
|
if (dict == NULL) {
|
||||||
|
printf("cannot find repository list file: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -149,22 +165,20 @@ main(int argc, char **argv)
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
dict =
|
xbps_callback_array_iter_in_dict(getrepolist_dict(),
|
||||||
prop_dictionary_internalize_from_file(XBPS_REPOLIST_PATH);
|
"repository-list", xbps_list_strings_in_array, NULL);
|
||||||
if (dict == NULL) {
|
|
||||||
printf("cannot find repository list file: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
exit(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
xbps_callback_array_iter_in_dict(dict, "repository-list",
|
|
||||||
xbps_list_strings_in_array);
|
|
||||||
|
|
||||||
} else if (strcmp(argv[1], "show") == 0) {
|
} else if (strcmp(argv[1], "show") == 0) {
|
||||||
/* Shows info about a binary package. */
|
/* Shows info about a binary package. */
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
if (!xbps_callback_array_iter_in_dict(getrepolist_dict(),
|
||||||
|
"repository-list", xbps_show_pkg_info_from_repolist,
|
||||||
|
argv[2])) {
|
||||||
|
printf("Package %s doesn't exist on any repository.\n",
|
||||||
|
argv[2]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
dbdict = prop_dictionary_internalize_from_file(dbfile);
|
dbdict = prop_dictionary_internalize_from_file(dbfile);
|
||||||
if (!xbps_callback_array_iter_in_dict(dbdict,
|
if (!xbps_callback_array_iter_in_dict(dbdict,
|
||||||
"packages", xbps_list_pkgs_in_dict))
|
"packages", xbps_list_pkgs_in_dict, NULL))
|
||||||
exit(EINVAL);
|
exit(EINVAL);
|
||||||
|
|
||||||
} else if (strcmp(argv[1], "version") == 0) {
|
} else if (strcmp(argv[1], "version") == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue