xbps-repo: added 'show-deps' target to mimic xbps-bin(8).

As consequence of this, remove xbps_callback_array_iter_in_repolist().
Nowadays to iter over the repository pool we have a SIMPLEQ, this
allowed to simplify the code and remove some now unneeed stuff.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091124104704-oyvrmb3tmd59w4e7
This commit is contained in:
Juan RP 2009-11-24 10:47:04 +00:00
parent c676622869
commit 164c661bcf
7 changed files with 82 additions and 164 deletions

View File

@ -33,29 +33,6 @@
#include "../xbps-repo/util.h" #include "../xbps-repo/util.h"
#include "defs.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 int
xbps_show_pkg_deps(const char *pkgname) 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", 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(propsd);
prop_object_release(pkgd); prop_object_release(pkgd);

View File

@ -44,13 +44,14 @@ usage(void)
{ {
printf("Usage: xbps-repo [options] [action] [arguments]\n\n" printf("Usage: xbps-repo [options] [action] [arguments]\n\n"
" Available actions:\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" " Actions with arguments:\n"
" add\t\t<URI>\n" " add\t\t<URI>\n"
" genindex\t<path>\n" " genindex\t<path>\n"
" remove\t<URI>\n" " remove\t<URI>\n"
" search\t<string>\n" " search\t<string>\n"
" show\t<pkgname>\n" " show\t<pkgname>\n"
" show-deps\t<pkgname>\n"
" Options shared by all actions:\n" " Options shared by all actions:\n"
" -r\t\t<rootdir>\n" " -r\t\t<rootdir>\n"
" -V\t\tPrints xbps release version\n" " -V\t\tPrints xbps release version\n"
@ -209,8 +210,10 @@ out:
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct repository_data *rdata = NULL; prop_dictionary_t pkgd;
char dpkgidx[PATH_MAX], *plist, *root = NULL; struct repository_data *rdata;
const char *pkgver;
char dpkgidx[PATH_MAX], *plist, *root;
int c, rv = 0; int c, rv = 0;
while ((c = getopt(argc, argv, "Vr:")) != -1) { while ((c = getopt(argc, argv, "Vr:")) != -1) {
@ -235,6 +238,14 @@ main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(); 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) { if (strcasecmp(argv[0], "add") == 0) {
/* Adds a new repository to the pool. */ /* Adds a new repository to the pool. */
if (argc != 2) if (argc != 2)
@ -247,8 +258,8 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
(void)xbps_callback_array_iter_in_repolist( SIMPLEQ_FOREACH(rdata, &repodata_queue, chain)
list_strings_sep_in_array, NULL); printf("%s\n", rdata->rd_uri);
} else if ((strcasecmp(argv[0], "rm") == 0) || } else if ((strcasecmp(argv[0], "rm") == 0) ||
(strcasecmp(argv[0], "remove") == 0)) { (strcasecmp(argv[0], "remove") == 0)) {
@ -256,8 +267,10 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
if (!sanitize_localpath(dpkgidx, argv[1])) if (!sanitize_localpath(dpkgidx, argv[1])) {
exit(EXIT_FAILURE); rv = EINVAL;
goto out;
}
if ((rv = xbps_unregister_repository(dpkgidx)) != 0) { if ((rv = xbps_unregister_repository(dpkgidx)) != 0) {
if (rv == ENOENT) if (rv == ENOENT)
@ -266,7 +279,6 @@ main(int argc, char **argv)
else else
printf("ERROR: couldn't unregister " printf("ERROR: couldn't unregister "
"repository (%s)\n", strerror(rv)); "repository (%s)\n", strerror(rv));
exit(EXIT_FAILURE);
} }
} else if (strcasecmp(argv[0], "search") == 0) { } else if (strcasecmp(argv[0], "search") == 0) {
@ -277,20 +289,62 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
(void)xbps_callback_array_iter_in_repolist( SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
search_string_in_pkgs, argv[1]); 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) { } else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */ /* Shows info about a binary package. */
if (argc != 2) if (argc != 2)
usage(); usage();
rv = xbps_callback_array_iter_in_repolist( SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
show_pkg_info_from_repolist, argv[1]); 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) { if (rv == 0 && errno == ENOENT) {
printf("Unable to locate package '%s' from " printf("Unable to locate package '%s' from "
"repository pool.\n", argv[1]); "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) { } else if (strcasecmp(argv[0], "genindex") == 0) {
@ -299,15 +353,12 @@ main(int argc, char **argv)
usage(); usage();
rv = xbps_repo_genindex(argv[1]); rv = xbps_repo_genindex(argv[1]);
exit(rv);
} else if (strcasecmp(argv[0], "sync") == 0) { } else if (strcasecmp(argv[0], "sync") == 0) {
/* Syncs the pkg index for all registered remote repos */ /* Syncs the pkg index for all registered remote repos */
if (argc != 1) if (argc != 1)
usage(); usage();
if ((rv = xbps_prepare_repolist_data()) != 0)
exit(rv);
/* /*
* Iterate over repository pool. * Iterate over repository pool.
*/ */
@ -319,7 +370,7 @@ main(int argc, char **argv)
if (rv == -1) { if (rv == -1) {
printf("Failed! returned: %s\n", printf("Failed! returned: %s\n",
xbps_fetch_error_string()); xbps_fetch_error_string());
break; goto out;
} else if (rv == 0) { } else if (rv == 0) {
printf("Package index file is already " printf("Package index file is already "
"up to date.\n"); "up to date.\n");
@ -328,17 +379,18 @@ main(int argc, char **argv)
plist = xbps_get_pkg_index_plist(uri); plist = xbps_get_pkg_index_plist(uri);
if (plist == NULL) { if (plist == NULL) {
rv = EINVAL; rv = EINVAL;
break; goto out;
} }
(void)pkgindex_verify(plist, uri, true); (void)pkgindex_verify(plist, uri, true);
free(plist); free(plist);
} }
} }
xbps_release_repolist_data();
} else { } else {
usage(); usage();
} }
exit(EXIT_SUCCESS); out:
xbps_release_repolist_data();
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -33,10 +33,7 @@
#include <xbps_api.h> #include <xbps_api.h>
#include "util.h" #include "util.h"
static void show_pkg_info(prop_dictionary_t); void
static int show_pkg_namedesc(prop_object_t, void *, bool *);
static void
show_pkg_info(prop_dictionary_t dict) show_pkg_info(prop_dictionary_t dict)
{ {
prop_object_t obj; prop_object_t obj;
@ -115,42 +112,6 @@ show_pkg_info(prop_dictionary_t dict)
printf(" %s\n", prop_string_cstring_nocopy(obj)); 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 int
show_pkg_info_from_metadir(const char *pkgname) show_pkg_info_from_metadir(const char *pkgname)
{ {
@ -252,45 +213,6 @@ out:
} }
int 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) show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
{ {
const char *pkgname, *desc, *ver, *pattern = arg; 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, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
prop_dictionary_get_cstring_nocopy(obj, "version", &ver); prop_dictionary_get_cstring_nocopy(obj, "version", &ver);
assert(ver != NULL);
if ((fnmatch(pattern, pkgname, 0) == 0) || if ((fnmatch(pattern, pkgname, 0) == 0) ||
(fnmatch(pattern, desc, 0) == 0)) (fnmatch(pattern, desc, 0) == 0))

View File

@ -26,10 +26,10 @@
#ifndef _XBPS_REPO_UTIL_H_ #ifndef _XBPS_REPO_UTIL_H_
#define _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_info_from_metadir(const char *);
int show_pkg_files_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_in_array(prop_object_t, void *, bool *);
int list_strings_sep_in_array(prop_object_t, void *, bool *); int list_strings_sep_in_array(prop_object_t, void *, bool *);

View File

@ -69,6 +69,10 @@ Please note that all targets are *case insensitive*.
the size it takes in filesystem, description, maintainer, architecture the size it takes in filesystem, description, maintainer, architecture
and other information. and other information.
*show-deps 'pkgname'*::
Shows run time dependencies for binary package 'pkgname'. The first
repository in the pool wins.
*sync*:: *sync*::
Syncs the package index file for all registered remote repositories. 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. The new file will be fetched if local and remote size/mtime do not match.

View File

@ -147,15 +147,13 @@ int SYMEXPORT xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t,
const char *, const char *,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(prop_object_t, void *, bool *),
void *); 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, prop_dictionary_t SYMEXPORT xbps_find_pkg_in_dict(prop_dictionary_t,
const char *, const char *); const char *, const char *);
prop_dictionary_t SYMEXPORT xbps_find_pkg_from_plist(const char *, prop_dictionary_t SYMEXPORT xbps_find_pkg_from_plist(const char *,
const char *); const char *);
prop_dictionary_t SYMEXPORT 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 *); bool SYMEXPORT xbps_find_string_in_array(prop_array_t, const char *);
prop_dictionary_t SYMEXPORT xbps_prepare_regpkgdb_dict(void); 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_CONFIG_FILES,
XBPS_PKG_STATE_NOT_INSTALLED XBPS_PKG_STATE_NOT_INSTALLED
} pkg_state_t; } pkg_state_t;
int SYMEXPORT xbps_get_pkg_state_installed(const char *, 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_get_pkg_state_dictionary(prop_dictionary_t, pkg_state_t *);
int SYMEXPORT xbps_set_pkg_state_installed(const char *, pkg_state_t); int SYMEXPORT xbps_set_pkg_state_installed(const char *, pkg_state_t);

View File

@ -66,41 +66,6 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
return true; 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 int SYMEXPORT
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,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(prop_object_t, void *, bool *),