diff --git a/bin/xbps-bin/show-deps.c b/bin/xbps-bin/show-deps.c index 0cbe7199..f1af7543 100644 --- a/bin/xbps-bin/show-deps.c +++ b/bin/xbps-bin/show-deps.c @@ -33,29 +33,6 @@ #include "../xbps-repo/util.h" #include "defs.h" -static int -list_deps(prop_object_t obj, void *arg, bool *loop_done) -{ - char *pkgname; - const char *version; - - (void)arg; - (void)loop_done; - - assert(prop_object_type(obj) == PROP_TYPE_STRING); - - pkgname = xbps_get_pkgdep_name(prop_string_cstring_nocopy(obj)); - version = xbps_get_pkgdep_version(prop_string_cstring_nocopy(obj)); - if (strcmp(version, ">=0") == 0) - printf("%s\n", pkgname); - else - printf("%s%s\n", pkgname, version); - - free(pkgname); - - return 0; -} - int xbps_show_pkg_deps(const char *pkgname) { @@ -88,7 +65,7 @@ xbps_show_pkg_deps(const char *pkgname) } rv = xbps_callback_array_iter_in_dict(propsd, "run_depends", - list_deps, NULL); + list_strings_sep_in_array, NULL); prop_object_release(propsd); prop_object_release(pkgd); diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 413cece4..dfdeff24 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -44,13 +44,14 @@ usage(void) { printf("Usage: xbps-repo [options] [action] [arguments]\n\n" " Available actions:\n" - " add, genindex, list, remove, search, show, sync\n" + " add, genindex, list, remove, search, show, show-deps, sync\n" " Actions with arguments:\n" " add\t\t\n" " genindex\t\n" " remove\t\n" " search\t\n" " show\t\n" + " show-deps\t\n" " Options shared by all actions:\n" " -r\t\t\n" " -V\t\tPrints xbps release version\n" @@ -209,8 +210,10 @@ out: int main(int argc, char **argv) { - struct repository_data *rdata = NULL; - char dpkgidx[PATH_MAX], *plist, *root = NULL; + prop_dictionary_t pkgd; + struct repository_data *rdata; + const char *pkgver; + char dpkgidx[PATH_MAX], *plist, *root; int c, rv = 0; while ((c = getopt(argc, argv, "Vr:")) != -1) { @@ -235,6 +238,14 @@ main(int argc, char **argv) if (argc < 1) usage(); + if ((rv = xbps_prepare_repolist_data()) != 0) { + if (rv != ENOENT) { + printf("E: cannot get repository list pool! %s\n", + strerror(rv)); + exit(EXIT_FAILURE); + } + } + if (strcasecmp(argv[0], "add") == 0) { /* Adds a new repository to the pool. */ if (argc != 2) @@ -247,8 +258,8 @@ main(int argc, char **argv) if (argc != 1) usage(); - (void)xbps_callback_array_iter_in_repolist( - list_strings_sep_in_array, NULL); + SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) + printf("%s\n", rdata->rd_uri); } else if ((strcasecmp(argv[0], "rm") == 0) || (strcasecmp(argv[0], "remove") == 0)) { @@ -256,8 +267,10 @@ main(int argc, char **argv) if (argc != 2) usage(); - if (!sanitize_localpath(dpkgidx, argv[1])) - exit(EXIT_FAILURE); + if (!sanitize_localpath(dpkgidx, argv[1])) { + rv = EINVAL; + goto out; + } if ((rv = xbps_unregister_repository(dpkgidx)) != 0) { if (rv == ENOENT) @@ -266,7 +279,6 @@ main(int argc, char **argv) else printf("ERROR: couldn't unregister " "repository (%s)\n", strerror(rv)); - exit(EXIT_FAILURE); } } else if (strcasecmp(argv[0], "search") == 0) { @@ -277,20 +289,62 @@ main(int argc, char **argv) if (argc != 2) usage(); - (void)xbps_callback_array_iter_in_repolist( - search_string_in_pkgs, argv[1]); + SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) { + printf("From %s repository ...\n", rdata->rd_uri); + (void)xbps_callback_array_iter_in_dict(rdata->rd_repod, + "packages", show_pkg_namedesc, argv[1]); + } } else if (strcasecmp(argv[0], "show") == 0) { /* Shows info about a binary package. */ if (argc != 2) usage(); - rv = xbps_callback_array_iter_in_repolist( - show_pkg_info_from_repolist, argv[1]); + SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) { + pkgd = xbps_find_pkg_in_dict(rdata->rd_repod, + "packages", argv[1]); + if (pkgd == NULL) { + errno = ENOENT; + continue; + } + printf("Repository: %s\n", rdata->rd_uri); + show_pkg_info(pkgd); + break; + } if (rv == 0 && errno == ENOENT) { printf("Unable to locate package '%s' from " "repository pool.\n", argv[1]); - exit(EXIT_FAILURE); + rv = EINVAL; + goto out; + } + + } else if (strcasecmp(argv[0], "show-deps") == 0) { + /* Shows the required run dependencies for a package. */ + if (argc != 2) + usage(); + + SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) { + pkgd = xbps_find_pkg_in_dict(rdata->rd_repod, + "packages", argv[1]); + if (pkgd == NULL) { + errno = ENOENT; + continue; + } + if (!prop_dictionary_get_cstring_nocopy(pkgd, + "version", &pkgver)) { + rv = errno; + goto out; + } + printf("Repository %s [pkgver: %s]\n", + rdata->rd_uri, pkgver); + (void)xbps_callback_array_iter_in_dict(pkgd, + "run_depends", list_strings_sep_in_array, NULL); + } + if (rv == 0 && errno == ENOENT) { + printf("Unable to locate package '%s' from " + "repository pool.\n", argv[1]); + rv = EINVAL; + goto out; } } else if (strcasecmp(argv[0], "genindex") == 0) { @@ -299,15 +353,12 @@ main(int argc, char **argv) usage(); rv = xbps_repo_genindex(argv[1]); - exit(rv); } else if (strcasecmp(argv[0], "sync") == 0) { /* Syncs the pkg index for all registered remote repos */ if (argc != 1) usage(); - if ((rv = xbps_prepare_repolist_data()) != 0) - exit(rv); /* * Iterate over repository pool. */ @@ -319,7 +370,7 @@ main(int argc, char **argv) if (rv == -1) { printf("Failed! returned: %s\n", xbps_fetch_error_string()); - break; + goto out; } else if (rv == 0) { printf("Package index file is already " "up to date.\n"); @@ -328,17 +379,18 @@ main(int argc, char **argv) plist = xbps_get_pkg_index_plist(uri); if (plist == NULL) { rv = EINVAL; - break; + goto out; } (void)pkgindex_verify(plist, uri, true); free(plist); } } - xbps_release_repolist_data(); } else { usage(); } - exit(EXIT_SUCCESS); +out: + xbps_release_repolist_data(); + exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 81433e1c..5f8c70d8 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -33,10 +33,7 @@ #include #include "util.h" -static void show_pkg_info(prop_dictionary_t); -static int show_pkg_namedesc(prop_object_t, void *, bool *); - -static void +void show_pkg_info(prop_dictionary_t dict) { prop_object_t obj; @@ -115,42 +112,6 @@ show_pkg_info(prop_dictionary_t dict) printf(" %s\n", prop_string_cstring_nocopy(obj)); } -int -search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done) -{ - prop_dictionary_t dict; - const char *repofile; - char *plist; - - (void)loop_done; - - assert(prop_object_type(obj) == PROP_TYPE_STRING); - - /* Get the location of pkgindex file. */ - repofile = prop_string_cstring_nocopy(obj); - assert(repofile != NULL); - - plist = xbps_get_pkg_index_plist(repofile); - if (plist == NULL) { - errno = ENOENT; - return 0; - } - - dict = prop_dictionary_internalize_from_file(plist); - if (dict == NULL) { - free(plist); - return 0; - } - - printf("From %s repository ...\n", repofile); - xbps_callback_array_iter_in_dict(dict, "packages", - show_pkg_namedesc, arg); - prop_object_release(dict); - free(plist); - - return 0; -} - int show_pkg_info_from_metadir(const char *pkgname) { @@ -252,45 +213,6 @@ out: } int -show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done) -{ - prop_dictionary_t dict, pkgdict; - const char *repofile; - char *plist; - assert(prop_object_type(obj) == PROP_TYPE_STRING); - - /* Get the location */ - repofile = prop_string_cstring_nocopy(obj); - - plist = xbps_get_pkg_index_plist(repofile); - if (plist == NULL) - return EINVAL; - - dict = prop_dictionary_internalize_from_file(plist); - if (dict == NULL || prop_dictionary_count(dict) == 0) { - free(plist); - errno = ENOENT; - return 0; - } - - pkgdict = xbps_find_pkg_in_dict(dict, "packages", arg); - if (pkgdict == NULL) { - prop_object_release(dict); - free(plist); - errno = ENOENT; - return 0; - } - - printf("Repository: %s\n", repofile); - show_pkg_info(pkgdict); - *loop_done = true; - prop_object_release(dict); - free(plist); - - return 0; -} - -static int show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) { const char *pkgname, *desc, *ver, *pattern = arg; @@ -303,7 +225,6 @@ show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(obj, "version", &ver); - assert(ver != NULL); if ((fnmatch(pattern, pkgname, 0) == 0) || (fnmatch(pattern, desc, 0) == 0)) diff --git a/bin/xbps-repo/util.h b/bin/xbps-repo/util.h index 92f5db2c..7294f6c4 100644 --- a/bin/xbps-repo/util.h +++ b/bin/xbps-repo/util.h @@ -26,10 +26,10 @@ #ifndef _XBPS_REPO_UTIL_H_ #define _XBPS_REPO_UTIL_H_ -int search_string_in_pkgs(prop_object_t, void *, bool *); +void show_pkg_info(prop_dictionary_t); 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 show_pkg_namedesc(prop_object_t, void *, bool *); int list_strings_in_array(prop_object_t, void *, bool *); int list_strings_sep_in_array(prop_object_t, void *, bool *); diff --git a/bin/xbps-repo/xbps-repo.8.txt b/bin/xbps-repo/xbps-repo.8.txt index 98ad217e..f8fc40fc 100644 --- a/bin/xbps-repo/xbps-repo.8.txt +++ b/bin/xbps-repo/xbps-repo.8.txt @@ -69,6 +69,10 @@ Please note that all targets are *case insensitive*. the size it takes in filesystem, description, maintainer, architecture and other information. +*show-deps 'pkgname'*:: + Shows run time dependencies for binary package 'pkgname'. The first + repository in the pool wins. + *sync*:: Syncs the package index file for all registered remote repositories. The new file will be fetched if local and remote size/mtime do not match. diff --git a/include/xbps_api.h b/include/xbps_api.h index e98b4228..624f86d4 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -147,15 +147,13 @@ int SYMEXPORT xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t, const char *, int (*fn)(prop_object_t, void *, bool *), void *); -int SYMEXPORT xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, - void *, bool *), void *); prop_dictionary_t SYMEXPORT xbps_find_pkg_in_dict(prop_dictionary_t, const char *, const char *); prop_dictionary_t SYMEXPORT xbps_find_pkg_from_plist(const char *, const char *); prop_dictionary_t SYMEXPORT - xbps_find_pkg_installed_from_plist(const char *); + xbps_find_pkg_installed_from_plist(const char *); bool SYMEXPORT xbps_find_string_in_array(prop_array_t, const char *); prop_dictionary_t SYMEXPORT xbps_prepare_regpkgdb_dict(void); @@ -201,6 +199,7 @@ typedef enum pkg_state { XBPS_PKG_STATE_CONFIG_FILES, XBPS_PKG_STATE_NOT_INSTALLED } pkg_state_t; + int SYMEXPORT xbps_get_pkg_state_installed(const char *, pkg_state_t *); int SYMEXPORT xbps_get_pkg_state_dictionary(prop_dictionary_t, pkg_state_t *); int SYMEXPORT xbps_set_pkg_state_installed(const char *, pkg_state_t); diff --git a/lib/plist.c b/lib/plist.c index 13951a8d..4de0d10b 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -66,41 +66,6 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj) return true; } -int SYMEXPORT -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(fn != NULL); - - plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, XBPS_REPOLIST); - if (plist == NULL) - return EINVAL; - - /* - * Get the dictionary with the list of registered repositories. - */ - repolistd = prop_dictionary_internalize_from_file(plist); - if (repolistd == NULL) - return EINVAL; - - /* - * Iterate over the repository pool and run the associated - * callback function. The loop is stopped when the bool - * argument is true or the cb returns non 0. - */ - rv = xbps_callback_array_iter_in_dict(repolistd, "repository-list", - fn, arg); - prop_object_release(repolistd); - free(plist); - - return rv; -} - int SYMEXPORT xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key, int (*fn)(prop_object_t, void *, bool *),