diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index d6889bd75f1..5a2f09fc491 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -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]); diff --git a/include/plist.h b/include/plist.h index 486d8bf45ff..c41cd14c2b8 100644 --- a/include/plist.h +++ b/include/plist.h @@ -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. diff --git a/lib/install.c b/lib/install.c index 73c8663ba04..6bf72c21b11 100644 --- a/lib/install.c +++ b/lib/install.c @@ -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; } diff --git a/lib/plist.c b/lib/plist.c index f1eda055244..2c7973db160 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -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; }