libxbps: require a pointer to xbps_handle in functions that need it.
This removes 2 global vars from lib/initend.c and easier to know what functions require access to xbps_handle.
This commit is contained in:
@@ -34,10 +34,9 @@
|
||||
#include "defs.h"
|
||||
|
||||
int
|
||||
cachedir_clean(void)
|
||||
cachedir_clean(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_dictionary_t pkg_propsd, repo_pkgd;
|
||||
struct xbps_handle *xhp = xbps_handle_get();
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
const char *pkgver, *rsha256;
|
||||
@@ -78,7 +77,7 @@ cachedir_clean(void)
|
||||
* Remove binary pkg if it's not registered in any repository
|
||||
* or if hash doesn't match.
|
||||
*/
|
||||
repo_pkgd = xbps_rpool_find_pkg_exact(pkgver);
|
||||
repo_pkgd = xbps_rpool_find_pkg_exact(xhp, pkgver);
|
||||
if (repo_pkgd) {
|
||||
prop_dictionary_get_cstring_nocopy(repo_pkgd,
|
||||
"filename-sha256", &rsha256);
|
||||
|
||||
@@ -35,25 +35,36 @@ struct repo_search_data {
|
||||
};
|
||||
|
||||
/* From index.c */
|
||||
int repo_genindex(const char *);
|
||||
int repo_genindex(struct xbps_handle *, const char *);
|
||||
|
||||
/* From index-files.c */
|
||||
int repo_genindex_files(const char *);
|
||||
int repo_genindex_files(struct xbps_handle *, const char *);
|
||||
|
||||
/* From find-files.c */
|
||||
int repo_find_files_in_packages(int, char **);
|
||||
int repo_find_files_in_packages(struct xbps_handle *, int, char **);
|
||||
|
||||
/* From list.c */
|
||||
int repo_pkg_list_cb(struct xbps_rpool_index *, void *, bool *);
|
||||
int repo_list_uri_cb(struct xbps_rpool_index *, void *, bool *);
|
||||
int repo_search_pkgs_cb(struct xbps_rpool_index *, void *, bool *);
|
||||
int repo_pkg_list_cb(struct xbps_handle *,
|
||||
struct xbps_rpool_index *,
|
||||
void *,
|
||||
bool *);
|
||||
int repo_list_uri_cb(struct xbps_handle *,
|
||||
struct xbps_rpool_index *,
|
||||
void *,
|
||||
bool *);
|
||||
int repo_search_pkgs_cb(struct xbps_handle *,
|
||||
struct xbps_rpool_index *,
|
||||
void *,
|
||||
bool *);
|
||||
|
||||
/* From show.c */
|
||||
int show_pkg_info_from_repolist(const char *, const char *);
|
||||
int show_pkg_deps_from_repolist(const char *);
|
||||
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
int show_pkg_info_from_repolist(struct xbps_handle *,
|
||||
const char *,
|
||||
const char *);
|
||||
int show_pkg_deps_from_repolist(struct xbps_handle *, const char *);
|
||||
int show_pkg_namedesc(struct xbps_handle *, prop_object_t, void *, bool *);
|
||||
|
||||
/* From clean.c */
|
||||
int cachedir_clean(void);
|
||||
int cachedir_clean(struct xbps_handle *);
|
||||
|
||||
#endif /* !_XBPS_REPO_DEFS_H_ */
|
||||
|
||||
@@ -66,7 +66,10 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, struct ffdata *ffd)
|
||||
}
|
||||
|
||||
static int
|
||||
find_files_in_package(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
find_files_in_package(struct xbps_handle *xhp,
|
||||
struct xbps_rpool_index *rpi,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
prop_array_t idxfiles;
|
||||
struct ffdata *ffd = arg;
|
||||
@@ -75,7 +78,7 @@ find_files_in_package(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
|
||||
(void)done;
|
||||
|
||||
if ((plist = xbps_pkg_index_files_plist(rpi->uri)) == NULL)
|
||||
if ((plist = xbps_pkg_index_files_plist(xhp, rpi->uri)) == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) {
|
||||
@@ -98,12 +101,14 @@ find_files_in_package(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
}
|
||||
|
||||
int
|
||||
repo_find_files_in_packages(int npatterns, char **patterns)
|
||||
repo_find_files_in_packages(struct xbps_handle *xhp,
|
||||
int npatterns,
|
||||
char **patterns)
|
||||
{
|
||||
struct ffdata ffd;
|
||||
|
||||
ffd.npatterns = npatterns;
|
||||
ffd.patterns = patterns;
|
||||
|
||||
return xbps_rpool_foreach(find_files_in_package, &ffd);
|
||||
return xbps_rpool_foreach(xhp, find_files_in_package, &ffd);
|
||||
}
|
||||
|
||||
@@ -42,12 +42,16 @@ struct index_files_data {
|
||||
};
|
||||
|
||||
static int
|
||||
rmobsoletes_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
rmobsoletes_files_cb(struct xbps_handle *xhp,
|
||||
prop_object_t obj,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
struct index_files_data *ifd = arg;
|
||||
const char *pkgver, *arch;
|
||||
char *str;
|
||||
|
||||
(void)xhp;
|
||||
(void)done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
@@ -70,7 +74,10 @@ rmobsoletes_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
}
|
||||
|
||||
static int
|
||||
genindex_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
genindex_files_cb(struct xbps_handle *xhp,
|
||||
prop_object_t obj,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
prop_object_t obj2, fileobj;
|
||||
prop_dictionary_t pkg_filesd, pkgd;
|
||||
@@ -81,6 +88,7 @@ genindex_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
bool found = false;
|
||||
size_t i;
|
||||
|
||||
(void)xhp;
|
||||
(void)done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &binpkg);
|
||||
@@ -211,7 +219,7 @@ genindex_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
* Create the index files cache for all packages in repository.
|
||||
*/
|
||||
int
|
||||
repo_genindex_files(const char *pkgdir)
|
||||
repo_genindex_files(struct xbps_handle *xhp, const char *pkgdir)
|
||||
{
|
||||
prop_array_t idx;
|
||||
struct index_files_data *ifd = NULL;
|
||||
@@ -220,7 +228,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
char *plist, *pkgver;
|
||||
int rv;
|
||||
|
||||
plist = xbps_pkg_index_plist(pkgdir);
|
||||
plist = xbps_pkg_index_plist(xhp, pkgdir);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -233,7 +241,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
free(plist);
|
||||
|
||||
/* internalize repository index-files plist (if exists) */
|
||||
plist = xbps_pkg_index_files_plist(pkgdir);
|
||||
plist = xbps_pkg_index_files_plist(xhp, pkgdir);
|
||||
if (plist == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out;
|
||||
@@ -255,7 +263,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
|
||||
/* remove obsolete pkg entries */
|
||||
if (!ifd->new) {
|
||||
rv = xbps_callback_array_iter(ifd->idxfiles,
|
||||
rv = xbps_callback_array_iter(xhp, ifd->idxfiles,
|
||||
rmobsoletes_files_cb, ifd);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
@@ -281,7 +289,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
}
|
||||
}
|
||||
/* iterate over index.plist array */
|
||||
if ((rv = xbps_callback_array_iter(idx, genindex_files_cb, ifd)) != 0)
|
||||
if ((rv = xbps_callback_array_iter(xhp, idx, genindex_files_cb, ifd)) != 0)
|
||||
goto out;
|
||||
|
||||
if (!ifd->flush)
|
||||
|
||||
@@ -47,7 +47,7 @@ static const char *archs[] = { "noarch", "i686", "x86_64" };
|
||||
* binary package cannot be read (unavailable, not enough perms, etc).
|
||||
*/
|
||||
static int
|
||||
remove_missing_binpkg_entries(const char *repodir)
|
||||
remove_missing_binpkg_entries(struct xbps_handle *xhp, const char *repodir)
|
||||
{
|
||||
prop_array_t array;
|
||||
prop_dictionary_t pkgd;
|
||||
@@ -57,7 +57,7 @@ remove_missing_binpkg_entries(const char *repodir)
|
||||
int rv = 0;
|
||||
bool found = false;
|
||||
|
||||
plist = xbps_pkg_index_plist(repodir);
|
||||
plist = xbps_pkg_index_plist(xhp, repodir);
|
||||
if (plist == NULL)
|
||||
return -1;
|
||||
|
||||
@@ -104,7 +104,7 @@ again:
|
||||
}
|
||||
|
||||
static prop_array_t
|
||||
repoidx_get(const char *pkgdir)
|
||||
repoidx_get(struct xbps_handle *xhp, const char *pkgdir)
|
||||
{
|
||||
prop_array_t array;
|
||||
char *plist;
|
||||
@@ -113,10 +113,10 @@ repoidx_get(const char *pkgdir)
|
||||
* Remove entries in repositories index for unexistent
|
||||
* packages, i.e dangling entries.
|
||||
*/
|
||||
if ((rv = remove_missing_binpkg_entries(pkgdir)) != 0)
|
||||
if ((rv = remove_missing_binpkg_entries(xhp, pkgdir)) != 0)
|
||||
return NULL;
|
||||
|
||||
plist = xbps_pkg_index_plist(pkgdir);
|
||||
plist = xbps_pkg_index_plist(xhp, pkgdir);
|
||||
if (plist == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -297,7 +297,7 @@ out:
|
||||
}
|
||||
|
||||
int
|
||||
repo_genindex(const char *pkgdir)
|
||||
repo_genindex(struct xbps_handle *xhp, const char *pkgdir)
|
||||
{
|
||||
prop_array_t idx = NULL;
|
||||
struct dirent *dp;
|
||||
@@ -311,11 +311,11 @@ repo_genindex(const char *pkgdir)
|
||||
/*
|
||||
* Create or read existing package index plist file.
|
||||
*/
|
||||
idx = repoidx_get(pkgdir);
|
||||
idx = repoidx_get(xhp, pkgdir);
|
||||
if (idx == NULL)
|
||||
return errno;
|
||||
|
||||
plist = xbps_pkg_index_plist(pkgdir);
|
||||
plist = xbps_pkg_index_plist(xhp, pkgdir);
|
||||
if (plist == NULL) {
|
||||
prop_object_release(idx);
|
||||
return errno;
|
||||
|
||||
@@ -35,7 +35,10 @@
|
||||
#include "../xbps-bin/defs.h"
|
||||
|
||||
int
|
||||
repo_pkg_list_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
repo_pkg_list_cb(struct xbps_handle *xhp,
|
||||
struct xbps_rpool_index *rpi,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
struct list_pkgver_cb lpc;
|
||||
const char *repo = arg;
|
||||
@@ -46,18 +49,22 @@ repo_pkg_list_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
|
||||
lpc.check_state = false;
|
||||
lpc.state = 0;
|
||||
lpc.pkgver_len = find_longest_pkgver(rpi->repo);
|
||||
lpc.pkgver_len = find_longest_pkgver(xhp, rpi->repo);
|
||||
|
||||
if (arg == NULL)
|
||||
printf("From %s repository ...\n", rpi->uri);
|
||||
|
||||
(void)xbps_callback_array_iter(rpi->repo, list_pkgs_in_dict, &lpc);
|
||||
(void)xbps_callback_array_iter(xhp, rpi->repo, list_pkgs_in_dict, &lpc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
repo_list_uri_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
repo_list_uri_cb(struct xbps_handle *xhp,
|
||||
struct xbps_rpool_index *rpi,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
(void)xhp;
|
||||
(void)arg;
|
||||
(void)done;
|
||||
|
||||
@@ -68,14 +75,17 @@ repo_list_uri_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
}
|
||||
|
||||
int
|
||||
repo_search_pkgs_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
|
||||
repo_search_pkgs_cb(struct xbps_handle *xhp,
|
||||
struct xbps_rpool_index *rpi,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
struct repo_search_data *rsd = arg;
|
||||
(void)done;
|
||||
|
||||
rsd->pkgver_len = find_longest_pkgver(rpi->repo);
|
||||
rsd->pkgver_len = find_longest_pkgver(xhp, rpi->repo);
|
||||
|
||||
printf("From %s repository ...\n", rpi->uri);
|
||||
(void)xbps_callback_array_iter(rpi->repo, show_pkg_namedesc, rsd);
|
||||
(void)xbps_callback_array_iter(xhp, rpi->repo, show_pkg_namedesc, rsd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
static void __attribute__((noreturn))
|
||||
usage(bool fail)
|
||||
{
|
||||
xbps_end();
|
||||
fprintf(stderr,
|
||||
"Usage: xbps-repo [options] target [arguments]\n\n"
|
||||
"[options]\n"
|
||||
@@ -151,7 +150,7 @@ main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
usage(true);
|
||||
|
||||
rv = xbps_rpool_foreach(repo_list_uri_cb, NULL);
|
||||
rv = xbps_rpool_foreach(&xh, repo_list_uri_cb, NULL);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
@@ -165,7 +164,7 @@ main(int argc, char **argv)
|
||||
if (argc < 1 || argc > 2)
|
||||
usage(true);
|
||||
|
||||
rv = xbps_rpool_foreach(repo_pkg_list_cb, argv[1]);
|
||||
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, argv[1]);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
@@ -187,7 +186,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
rsd->npatterns = argc;
|
||||
rsd->patterns = argv;
|
||||
rv = xbps_rpool_foreach(repo_search_pkgs_cb, rsd);
|
||||
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, rsd);
|
||||
free(rsd);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
@@ -200,7 +199,7 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage(true);
|
||||
|
||||
rv = show_pkg_info_from_repolist(argv[1], option);
|
||||
rv = show_pkg_info_from_repolist(&xh, argv[1], option);
|
||||
if (rv == ENOENT) {
|
||||
xbps_error_printf("Unable to locate package "
|
||||
"`%s' in repository pool.\n", argv[1]);
|
||||
@@ -216,7 +215,7 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage(true);
|
||||
|
||||
rv = show_pkg_deps_from_repolist(argv[1]);
|
||||
rv = show_pkg_deps_from_repolist(&xh, argv[1]);
|
||||
if (rv == ENOENT) {
|
||||
xbps_error_printf("Unable to locate package "
|
||||
"`%s' in repository pool.\n", argv[1]);
|
||||
@@ -232,7 +231,7 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage(true);
|
||||
|
||||
pkgd = xbps_rpool_dictionary_metadata_plist(argv[1],
|
||||
pkgd = xbps_rpool_dictionary_metadata_plist(&xh, argv[1],
|
||||
"./files.plist");
|
||||
if (pkgd == NULL) {
|
||||
if (errno == ENOTSUP) {
|
||||
@@ -256,7 +255,7 @@ main(int argc, char **argv)
|
||||
if (argc < 2)
|
||||
usage(true);
|
||||
|
||||
rv = repo_find_files_in_packages(argc, argv);
|
||||
rv = repo_find_files_in_packages(&xh, argc, argv);
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
@@ -266,16 +265,16 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage(true);
|
||||
|
||||
rv = repo_genindex(argv[1]);
|
||||
rv = repo_genindex(&xh, argv[1]);
|
||||
if (rv == 0)
|
||||
rv = repo_genindex_files(argv[1]);
|
||||
rv = repo_genindex_files(&xh, argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "sync") == 0) {
|
||||
/* Syncs the pkg index for all registered remote repos */
|
||||
if (argc < 1 || argc > 2)
|
||||
usage(true);
|
||||
|
||||
rv = xbps_rpool_sync(argv[1]);
|
||||
rv = xbps_rpool_sync(&xh, argv[1]);
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
@@ -285,12 +284,12 @@ main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
usage(true);
|
||||
|
||||
rv = cachedir_clean();
|
||||
rv = cachedir_clean(&xh);
|
||||
} else {
|
||||
usage(true);
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_end();
|
||||
xbps_end(&xh);
|
||||
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -44,14 +44,16 @@
|
||||
#include "defs.h"
|
||||
|
||||
int
|
||||
show_pkg_info_from_repolist(const char *pattern, const char *option)
|
||||
show_pkg_info_from_repolist(struct xbps_handle *xhp,
|
||||
const char *pattern,
|
||||
const char *option)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
|
||||
if (xbps_pkgpattern_version(pattern))
|
||||
pkgd = xbps_rpool_find_pkg(pattern, true, false);
|
||||
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
|
||||
else
|
||||
pkgd = xbps_rpool_find_pkg(pattern, false, true);
|
||||
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
|
||||
|
||||
if (pkgd == NULL)
|
||||
return errno;
|
||||
@@ -67,15 +69,15 @@ show_pkg_info_from_repolist(const char *pattern, const char *option)
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_deps_from_repolist(const char *pattern)
|
||||
show_pkg_deps_from_repolist(struct xbps_handle *xhp, const char *pattern)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
const char *ver, *repoloc;
|
||||
|
||||
if (xbps_pkgpattern_version(pattern))
|
||||
pkgd = xbps_rpool_find_pkg(pattern, true, false);
|
||||
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
|
||||
else
|
||||
pkgd = xbps_rpool_find_pkg(pattern, false, true);
|
||||
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
|
||||
|
||||
if (pkgd == NULL)
|
||||
return errno;
|
||||
@@ -84,7 +86,7 @@ show_pkg_deps_from_repolist(const char *pattern)
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
|
||||
|
||||
printf("Repository %s [pkgver: %s]\n", repoloc, ver);
|
||||
(void)xbps_callback_array_iter_in_dict(pkgd,
|
||||
(void)xbps_callback_array_iter_in_dict(xhp, pkgd,
|
||||
"run_depends", list_strings_sep_in_array, NULL);
|
||||
|
||||
prop_object_release(pkgd);
|
||||
@@ -92,13 +94,17 @@ show_pkg_deps_from_repolist(const char *pattern)
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
||||
show_pkg_namedesc(struct xbps_handle *xhp,
|
||||
prop_object_t obj,
|
||||
void *arg,
|
||||
bool *loop_done)
|
||||
{
|
||||
struct repo_search_data *rsd = arg;
|
||||
const char *pkgver, *pkgname, *desc, *arch;
|
||||
char *tmp = NULL;
|
||||
size_t i, x;
|
||||
|
||||
(void)xhp;
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
|
||||
Reference in New Issue
Block a user