Use xbps_callback_array_iter_in_repolist() and removed dup code.

--HG--
extra : convert_revision : 7eb9c1b3df3fc7fde2ff61ac0cce1d635c3fef18
This commit is contained in:
Juan RP 2009-02-14 02:26:11 +01:00
parent 90fd3828e6
commit 83ed100fcf
4 changed files with 16 additions and 57 deletions

View file

@ -43,12 +43,9 @@ typedef struct repository_info {
} repo_info_t;
static bool sanitize_localpath(char *, const char *);
static prop_dictionary_t getrepolist_dict(const char *);
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
static void usage(void);
static char *plist;
static void
usage(void)
{
@ -101,28 +98,6 @@ pkgindex_getinfo(prop_dictionary_t dict, repo_info_t *ri)
return true;
}
static prop_dictionary_t
getrepolist_dict(const char *root)
{
prop_dictionary_t dict;
xbps_set_rootdir(root);
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
exit(EXIT_FAILURE);
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
printf("ERROR: cannot find repository plist file (%s).\n",
strerror(errno));
free(plist);
exit(EXIT_FAILURE);
}
return dict;
}
static bool
sanitize_localpath(char *buf, const char *path)
{
@ -169,7 +144,7 @@ main(int argc, char **argv)
{
prop_dictionary_t dict;
repo_info_t *rinfo = NULL;
char dpkgidx[PATH_MAX], *root = NULL;
char dpkgidx[PATH_MAX], *plist, *root = NULL;
int c, rv = 0;
while ((c = getopt(argc, argv, "r:")) != -1) {
@ -249,11 +224,8 @@ main(int argc, char **argv)
if (argc != 1)
usage();
dict = getrepolist_dict(root);
(void)xbps_callback_array_iter_in_dict(dict,
"repository-list", list_strings_in_array, NULL);
prop_object_release(dict);
free(plist);
(void)xbps_callback_array_iter_in_repolist(
list_strings_in_array, NULL);
} else if ((strcasecmp(argv[0], "rm") == 0) ||
(strcasecmp(argv[0], "remove") == 0)) {
@ -279,23 +251,16 @@ main(int argc, char **argv)
if (argc != 2)
usage();
dict = getrepolist_dict(root);
(void)xbps_callback_array_iter_in_dict(dict,
"repository-list", search_string_in_pkgs, argv[1]);
prop_object_release(dict);
free(plist);
(void)xbps_callback_array_iter_in_repolist(
search_string_in_pkgs, argv[1]);
} else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */
if (argc != 2)
usage();
dict = getrepolist_dict(root);
rv = xbps_callback_array_iter_in_dict(dict, "repository-list",
rv = xbps_callback_array_iter_in_repolist(
show_pkg_info_from_repolist, argv[1]);
prop_object_release(dict);
free(plist);
if (rv == 0 && errno == ENOENT) {
printf("Unable to locate package '%s' from "
"repository pool.\n", argv[1]);

View file

@ -47,8 +47,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t, const char *,
int (*fn)(prop_object_t, void *, bool *),
void *);
int
xbps_callback_array_iter_in_repolist(const char *,
int (*fn)(prop_object_t, void *, bool *),
xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, void *, bool *),
void *);
/*
* Finds a package's dictionary into the main dictionary.

View file

@ -70,7 +70,6 @@ int
xbps_install_binary_pkg(const char *pkgname, const char *destdir)
{
struct cbargs cb;
char *plist;
int rv = 0;
assert(pkgname != NULL);
@ -80,22 +79,14 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
} else
destdir = "NOTSET";
/*
* Get the dictionary with the list of registered repositories.
*/
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL;
cb.pkgname = pkgname;
cb.destdir = destdir;
/*
* Iterate over the repository pool and find out if we have
* all available binary packages.
*/
rv = xbps_callback_array_iter_in_repolist(plist,
install_binpkg_repo_cb, (void *)&cb);
free(plist);
rv = xbps_callback_array_iter_in_repolist(install_binpkg_repo_cb,
(void *)&cb);
return rv;
}

View file

@ -66,16 +66,19 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
}
int
xbps_callback_array_iter_in_repolist(const char *plist,
int (*fn)(prop_object_t, void *, bool *),
xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, void *, bool *),
void *arg)
{
prop_dictionary_t repolistd;
char *plist;
int rv = 0;
assert(plist != NULL);
assert(fn != NULL);
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL;
/*
* Get the dictionary with the list of registered repositories.
*/
@ -91,6 +94,7 @@ xbps_callback_array_iter_in_repolist(const char *plist,
rv = xbps_callback_array_iter_in_dict(repolistd, "repository-list",
fn, arg);
prop_object_release(repolistd);
free(plist);
return rv;
}