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:
Juan RP
2012-06-14 08:22:11 +02:00
parent a3adbcda95
commit 3e9e87fc2a
60 changed files with 1143 additions and 901 deletions

View File

@@ -42,7 +42,10 @@ struct checkpkg {
};
static int
cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
cb_pkg_integrity(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *done)
{
struct checkpkg *cpkg = arg;
const char *pkgname, *version;
@@ -54,7 +57,7 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
printf("[%zu/%zu] checking %s-%s ...\n",
cpkg->npkgs, cpkg->totalpkgs, pkgname, version);
if (check_pkg_integrity(obj, pkgname, false, &flush) != 0)
if (check_pkg_integrity(xhp, obj, pkgname, false, &flush) != 0)
cpkg->nbrokenpkgs++;
else
printf("\033[1A\033[K");
@@ -67,20 +70,19 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
}
int
check_pkg_integrity_all(void)
check_pkg_integrity_all(struct xbps_handle *xhp)
{
struct xbps_handle *xhp = xbps_handle_get();
struct checkpkg cpkg;
int rv;
memset(&cpkg, 0, sizeof(cpkg));
/* force an update to get total pkg count */
(void)xbps_pkgdb_update(false);
(void)xbps_pkgdb_update(xhp, false);
cpkg.totalpkgs = prop_array_count(xhp->pkgdb);
(void)xbps_pkgdb_foreach_cb(cb_pkg_integrity, &cpkg);
(void)xbps_pkgdb_foreach_cb(xhp, cb_pkg_integrity, &cpkg);
if (cpkg.flush) {
if ((rv = xbps_pkgdb_update(true)) != 0) {
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write pkgdb: %s\n",
strerror(rv));
return rv;
@@ -92,7 +94,8 @@ check_pkg_integrity_all(void)
}
int
check_pkg_integrity(prop_dictionary_t pkgd,
check_pkg_integrity(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkgname,
bool flush,
bool *setflush)
@@ -105,11 +108,11 @@ check_pkg_integrity(prop_dictionary_t pkgd,
/* find real pkg by name */
if (pkgd == NULL) {
opkgd = xbps_find_pkg_dict_installed(pkgname, false);
opkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (opkgd == NULL) {
/* find virtual pkg by name */
opkgd = xbps_find_virtualpkg_dict_installed(pkgname,
false);
opkgd = xbps_find_virtualpkg_dict_installed(xhp,
pkgname, false);
}
if (opkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
@@ -119,7 +122,7 @@ check_pkg_integrity(prop_dictionary_t pkgd,
/*
* Check for props.plist metadata file.
*/
propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS);
propsd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS);
if (propsd == NULL) {
xbps_error_printf("%s: unexistent %s or invalid metadata "
"file.\n", pkgname, XBPS_PKGPROPS);
@@ -134,7 +137,7 @@ check_pkg_integrity(prop_dictionary_t pkgd,
/*
* Check for files.plist metadata file.
*/
filesd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
filesd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (filesd == NULL) {
xbps_error_printf("%s: unexistent %s or invalid metadata "
"file.\n", pkgname, XBPS_PKGFILES);
@@ -147,9 +150,9 @@ check_pkg_integrity(prop_dictionary_t pkgd,
goto out;
}
#define RUN_PKG_CHECK(name, arg, arg2) \
#define RUN_PKG_CHECK(x, name, arg, arg2) \
do { \
rv = check_pkg_##name(pkgname, arg, arg2); \
rv = check_pkg_##name(x, pkgname, arg, arg2); \
if (rv) \
broken = true; \
else if (rv == -1) { \
@@ -160,14 +163,14 @@ do { \
} while (0)
/* Execute pkg checks */
RUN_PKG_CHECK(files, filesd, &pkgdb_update);
RUN_PKG_CHECK(symlinks, filesd, &pkgdb_update);
RUN_PKG_CHECK(rundeps, propsd, &pkgdb_update);
RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(xhp, files, filesd, &pkgdb_update);
RUN_PKG_CHECK(xhp, symlinks, filesd, &pkgdb_update);
RUN_PKG_CHECK(xhp, rundeps, propsd, &pkgdb_update);
RUN_PKG_CHECK(xhp, requiredby, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(xhp, autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update);
if (flush && pkgdb_update) {
if (!xbps_pkgdb_replace_pkgd(opkgd, pkgname, false, true)) {
if (!xbps_pkgdb_replace_pkgd(xhp, opkgd, pkgname, false, true)) {
rv = EINVAL;
goto out;
}

View File

@@ -47,12 +47,16 @@
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_autoinstall(const char *pkgname, void *arg, bool *pkgdb_update)
check_pkg_autoinstall(struct xbps_handle *xhp,
const char *pkgname,
void *arg,
bool *pkgdb_update)
{
prop_dictionary_t pkgd = arg;
prop_array_t reqby;
bool autoinst = false;
(void)xhp;
/*
* Check if package has been installed manually but any other
* package is currently depending on it; in that case the package

View File

@@ -46,9 +46,11 @@
* Return 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_files(const char *pkgname, void *arg, bool *pkgdb_update)
check_pkg_files(struct xbps_handle *xhp,
const char *pkgname,
void *arg,
bool *pkgdb_update)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter;

View File

@@ -43,7 +43,10 @@ struct check_reqby_data {
};
static int
check_reqby_pkg_cb(prop_object_t obj, void *arg, bool *done)
check_reqby_pkg_cb(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *done)
{
struct check_reqby_data *crd = arg;
prop_array_t curpkg_rdeps, provides;
@@ -63,7 +66,7 @@ check_reqby_pkg_cb(prop_object_t obj, void *arg, bool *done)
* installed metadata directory.
*/
curpkg_propsd =
xbps_dictionary_from_metadata_plist(curpkgn, XBPS_PKGPROPS);
xbps_dictionary_from_metadata_plist(xhp, curpkgn, XBPS_PKGPROPS);
if (curpkg_propsd == NULL) {
xbps_error_printf("%s: missing %s metadata file!\n",
curpkgn, XBPS_PKGPROPS);
@@ -142,7 +145,8 @@ check_reqby_pkg_cb(prop_object_t obj, void *arg, bool *done)
* Removes unused entries in pkg's requiredby array.
*/
static bool
remove_stale_entries_in_reqby(struct check_reqby_data *crd)
remove_stale_entries_in_reqby(struct xbps_handle *xhp,
struct check_reqby_data *crd)
{
prop_array_t reqby;
prop_dictionary_t pkgd;
@@ -158,7 +162,7 @@ remove_stale_entries_in_reqby(struct check_reqby_data *crd)
for (i = 0; i < prop_array_count(reqby); i++) {
prop_array_get_cstring_nocopy(reqby, i, &str);
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(str)) != NULL) {
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL) {
prop_object_release(pkgd);
continue;
}
@@ -185,7 +189,10 @@ remove_stale_entries_in_reqby(struct check_reqby_data *crd)
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_requiredby(const char *pkgname, void *arg, bool *pkgdb_update)
check_pkg_requiredby(struct xbps_handle *xhp,
const char *pkgname,
void *arg,
bool *pkgdb_update)
{
prop_dictionary_t pkgd = arg;
struct check_reqby_data crd;
@@ -198,7 +205,7 @@ check_pkg_requiredby(const char *pkgname, void *arg, bool *pkgdb_update)
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &crd.pkgver);
/* missing reqby entries in pkgs */
rv = xbps_pkgdb_foreach_cb(check_reqby_pkg_cb, &crd);
rv = xbps_pkgdb_foreach_cb(xhp, check_reqby_pkg_cb, &crd);
if (rv < 0) {
return rv;
} else if (rv == 1) {
@@ -210,7 +217,7 @@ check_pkg_requiredby(const char *pkgname, void *arg, bool *pkgdb_update)
printf("%s: requiredby fix done!\n\n", crd.pkgver);
}
/* remove stale entries in pkg's reqby */
if (remove_stale_entries_in_reqby(&crd))
if (remove_stale_entries_in_reqby(xhp, &crd))
*pkgdb_update = true;
return 0;

View File

@@ -45,7 +45,10 @@
*/
int
check_pkg_rundeps(const char *pkgname, void *arg, bool *pkgdb_update)
check_pkg_rundeps(struct xbps_handle *xhp,
const char *pkgname,
void *arg,
bool *pkgdb_update)
{
prop_dictionary_t pkg_propsd = arg;
prop_object_t obj;
@@ -68,7 +71,7 @@ check_pkg_rundeps(const char *pkgname, void *arg, bool *pkgdb_update)
prop_object_iterator_release(iter);
return -1;
}
if (xbps_check_is_installed_pkg_by_pattern(reqpkg) <= 0) {
if (xbps_check_is_installed_pkg_by_pattern(xhp, reqpkg) <= 0) {
xbps_error_printf("%s: dependency not satisfied: %s\n",
pkgname, reqpkg);
test_broken = true;

View File

@@ -45,9 +45,11 @@
* returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_symlinks(const char *pkgname, void *arg, bool *pkgdb_update)
check_pkg_symlinks(struct xbps_handle *xhp,
const char *pkgname,
void *arg,
bool *pkgdb_update)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter;

View File

@@ -29,6 +29,10 @@
#include <sys/time.h>
#include <xbps_api.h>
#ifndef __UNCONST
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#endif
struct xferstat {
struct timeval start;
struct timeval last;
@@ -41,22 +45,26 @@ struct list_pkgver_cb {
};
/* from transaction.c */
int install_new_pkg(const char *, bool);
int update_pkg(const char *);
int remove_pkg(const char *, bool);
int remove_pkg_orphans(bool, bool);
int dist_upgrade(bool, bool, bool);
int exec_transaction(bool, bool, bool);
int install_new_pkg(struct xbps_handle *, const char *, bool);
int update_pkg(struct xbps_handle *, const char *);
int remove_pkg(struct xbps_handle *, const char *, bool);
int remove_pkg_orphans(struct xbps_handle *, bool, bool);
int dist_upgrade(struct xbps_handle *, bool, bool, bool);
int exec_transaction(struct xbps_handle *, bool, bool, bool);
/* from remove.c */
int remove_installed_pkgs(int, char **, bool, bool, bool, bool);
/* from check.c */
int check_pkg_integrity(prop_dictionary_t, const char *, bool, bool *);
int check_pkg_integrity_all(void);
int check_pkg_integrity(struct xbps_handle *,
prop_dictionary_t,
const char *,
bool,
bool *);
int check_pkg_integrity_all(struct xbps_handle *);
#define CHECK_PKG_DECL(type) \
int check_pkg_##type (const char *, void *, bool *)
int check_pkg_##type (struct xbps_handle *, const char *, void *, bool *)
CHECK_PKG_DECL(autoinstall);
CHECK_PKG_DECL(files);
@@ -65,43 +73,54 @@ CHECK_PKG_DECL(symlinks);
CHECK_PKG_DECL(requiredby);
/* from show-deps.c */
int show_pkg_deps(const char *);
int show_pkg_reverse_deps(const char *);
int show_pkg_deps(struct xbps_handle *, const char *);
int show_pkg_reverse_deps(struct xbps_handle *, const char *);
/* from show-info-files.c */
int show_pkg_info_from_metadir(const char *, const char *);
int show_pkg_files_from_metadir(const char *);
int show_pkg_info_from_metadir(struct xbps_handle *, const char *, const char *);
int show_pkg_files_from_metadir(struct xbps_handle *, const char *);
/* from show-orphans.c */
int show_orphans(void);
int show_orphans(struct xbps_handle *);
/* from find-files.c */
int find_files_in_packages(int, char **);
int find_files_in_packages(struct xbps_handle *, int, char **);
/* from question.c */
bool yesno(const char *, ...);
bool noyes(const char *, ...);
/* from fetch_cb.c */
void fetch_file_progress_cb(const struct xbps_fetch_cb_data *, void *);
void fetch_file_progress_cb(struct xbps_handle *,
struct xbps_fetch_cb_data *,
void *);
/* from state_cb.c */
void state_cb(const struct xbps_state_cb_data *, void *);
void state_cb(struct xbps_handle *,
struct xbps_state_cb_data *,
void *);
/* from unpack_cb.c */
void unpack_progress_cb_verbose(const struct xbps_unpack_cb_data *, void *);
void unpack_progress_cb(const struct xbps_unpack_cb_data *, void *);
void unpack_progress_cb_verbose(struct xbps_handle *,
struct xbps_unpack_cb_data *,
void *);
void unpack_progress_cb(struct xbps_handle *,
struct xbps_unpack_cb_data *,
void *);
/* From util.c */
int show_pkg_files(prop_dictionary_t);
void show_pkg_info(prop_dictionary_t);
void show_pkg_info_one(prop_dictionary_t, const char *);
int list_strings_sep_in_array(prop_object_t, void *, bool *);
size_t find_longest_pkgver(prop_object_t);
int list_strings_sep_in_array(struct xbps_handle *,
prop_object_t,
void *,
bool *);
size_t find_longest_pkgver(struct xbps_handle *, prop_object_t);
void print_package_line(const char *, bool);
/* from list.c */
int list_pkgs_in_dict(prop_object_t, void *, bool *);
int list_manual_pkgs(prop_object_t, void *, bool *);
int list_pkgs_in_dict(struct xbps_handle *, prop_object_t, void *, bool *);
int list_manual_pkgs(struct xbps_handle *, prop_object_t, void *, bool *);
#endif /* !_XBPS_BIN_DEFS_H_ */

View File

@@ -61,7 +61,7 @@ get_time(struct timeval *tvp)
* Compute and display ETA
*/
static const char *
stat_eta(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
stat_eta(struct xbps_fetch_cb_data *xfpd, void *cbdata)
{
struct xferstat *xfer = cbdata;
static char str[16];
@@ -100,7 +100,7 @@ compare_double(const double a, const double b)
* Compute and display transfer rate
*/
static const char *
stat_bps(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
stat_bps(struct xbps_fetch_cb_data *xfpd, void *cbdata)
{
struct xferstat *xfer = cbdata;
static char str[16];
@@ -124,7 +124,7 @@ stat_bps(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
* Update the stats display
*/
static void
stat_display(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
stat_display(struct xbps_fetch_cb_data *xfpd, void *cbdata)
{
struct xferstat *xfer = cbdata;
struct timeval now;
@@ -151,11 +151,15 @@ stat_display(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
}
void
fetch_file_progress_cb(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
fetch_file_progress_cb(struct xbps_handle *xhp,
struct xbps_fetch_cb_data *xfpd,
void *cbdata)
{
struct xferstat *xfer = cbdata;
char size[8];
(void)xhp;
if (xfpd->cb_start) {
/* start transfer stats */
get_time(&xfer->start);

View File

@@ -75,9 +75,8 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd,
}
int
find_files_in_packages(int npatterns, char **patterns)
find_files_in_packages(struct xbps_handle *xhp, int npatterns, char **patterns)
{
struct xbps_handle *xhp;
prop_dictionary_t pkg_filesd;
prop_array_t files_keys;
DIR *dirp;
@@ -86,7 +85,6 @@ find_files_in_packages(int npatterns, char **patterns)
int rv = 0;
unsigned int i, count;
xhp = xbps_handle_get();
path = xbps_xasprintf("%s/metadata", xhp->metadir);
if (path == NULL)
return -1;
@@ -101,8 +99,8 @@ find_files_in_packages(int npatterns, char **patterns)
(strcmp(dp->d_name, "..") == 0))
continue;
pkg_filesd = xbps_dictionary_from_metadata_plist(dp->d_name,
XBPS_PKGFILES);
pkg_filesd = xbps_dictionary_from_metadata_plist(xhp,
dp->d_name, XBPS_PKGFILES);
if (pkg_filesd == NULL) {
if (errno == ENOENT)
continue;

View File

@@ -33,7 +33,10 @@
#include "compat.h"
int
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
list_pkgs_in_dict(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
struct list_pkgver_cb *lpc = arg;
const char *pkgver, *short_desc, *arch;
@@ -42,6 +45,7 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
size_t i = 0;
bool chkarch;
(void)xhp;
(void)loop_done;
chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
@@ -82,11 +86,15 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
}
int
list_manual_pkgs(prop_object_t obj, void *arg, bool *loop_done)
list_manual_pkgs(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
const char *pkgver;
bool automatic = false;
(void)xhp;
(void)arg;
(void)loop_done;

View File

@@ -41,7 +41,6 @@
static void __attribute__((noreturn))
usage(bool fail)
{
xbps_end();
fprintf(stderr,
"Usage: xbps-bin [options] target [arguments]\n\n"
"[options]\n"
@@ -100,7 +99,6 @@ usage(bool fail)
static void __attribute__((noreturn))
cleanup(int signum)
{
xbps_end();
exit(signum);
}
@@ -256,8 +254,8 @@ main(int argc, char **argv)
/*
* Find the longest pkgver string to pretty print the output.
*/
lpc.pkgver_len = find_longest_pkgver(NULL);
rv = xbps_pkgdb_foreach_cb(list_pkgs_in_dict, &lpc);
lpc.pkgver_len = find_longest_pkgver(&xh, NULL);
rv = xbps_pkgdb_foreach_cb(&xh, list_pkgs_in_dict, &lpc);
if (rv == ENOENT) {
printf("No packages currently registered.\n");
rv = 0;
@@ -268,28 +266,28 @@ main(int argc, char **argv)
if (argc < 2)
usage(true);
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
if (sync && ((rv = xbps_rpool_sync(&xh, NULL)) != 0))
goto out;
for (i = 1; i < argc; i++)
if ((rv = install_new_pkg(argv[i], reinstall)) != 0)
if ((rv = install_new_pkg(&xh, argv[i], reinstall)) != 0)
goto out;
rv = exec_transaction(yes, dry_run, show_download_pkglist_url);
rv = exec_transaction(&xh, yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "update") == 0) {
/* Update an installed package. */
if (argc < 2)
usage(true);
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
if (sync && ((rv = xbps_rpool_sync(&xh, NULL)) != 0))
goto out;
for (i = 1; i < argc; i++)
if ((rv = update_pkg(argv[i])) != 0)
if ((rv = update_pkg(&xh, argv[i])) != 0)
goto out;
rv = exec_transaction(yes, dry_run, show_download_pkglist_url);
rv = exec_transaction(&xh, yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "remove") == 0) {
/* Removes a package. */
@@ -297,7 +295,7 @@ main(int argc, char **argv)
usage(true);
for (i = 1; i < argc; i++) {
rv = remove_pkg(argv[i], recursive_rm);
rv = remove_pkg(&xh, argv[i], recursive_rm);
if (rv == 0)
continue;
else if (rv != EEXIST)
@@ -309,14 +307,14 @@ main(int argc, char **argv)
rv = EINVAL;
goto out;
}
rv = exec_transaction(yes, dry_run, false);
rv = exec_transaction(&xh, yes, dry_run, false);
} else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about an installed binary package. */
if (argc != 2)
usage(true);
rv = show_pkg_info_from_metadir(argv[1], option);
rv = show_pkg_info_from_metadir(&xh, argv[1], option);
if (rv != 0) {
printf("Package %s not installed.\n", argv[1]);
goto out;
@@ -327,7 +325,7 @@ main(int argc, char **argv)
if (argc != 2)
usage(true);
rv = show_pkg_files_from_metadir(argv[1]);
rv = show_pkg_files_from_metadir(&xh, argv[1]);
if (rv != 0) {
printf("Package %s not installed.\n", argv[1]);
goto out;
@@ -339,9 +337,9 @@ main(int argc, char **argv)
usage(true);
if (strcasecmp(argv[1], "all") == 0)
rv = check_pkg_integrity_all();
rv = check_pkg_integrity_all(&xh);
else
rv = check_pkg_integrity(NULL, argv[1], true, NULL);
rv = check_pkg_integrity(&xh, NULL, argv[1], true, NULL);
} else if ((strcasecmp(argv[0], "dist-upgrade") == 0) ||
(strcasecmp(argv[0], "autoupdate") == 0)) {
@@ -351,10 +349,10 @@ main(int argc, char **argv)
if (argc != 1)
usage(true);
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
if (sync && ((rv = xbps_rpool_sync(&xh, NULL)) != 0))
goto out;
rv = dist_upgrade(yes, dry_run, show_download_pkglist_url);
rv = dist_upgrade(&xh, yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "show-orphans") == 0) {
/*
@@ -364,7 +362,7 @@ main(int argc, char **argv)
if (argc != 1)
usage(true);
rv = show_orphans();
rv = show_orphans(&xh);
} else if ((strcasecmp(argv[0], "remove-orphans") == 0) ||
(strcasecmp(argv[0], "autoremove") == 0)) {
@@ -376,7 +374,7 @@ main(int argc, char **argv)
if (argc != 1)
usage(true);
rv = remove_pkg_orphans(yes, dry_run);
rv = remove_pkg_orphans(&xh, yes, dry_run);
} else if (strcasecmp(argv[0], "reconfigure") == 0) {
/*
@@ -386,9 +384,9 @@ main(int argc, char **argv)
usage(true);
if (strcasecmp(argv[1], "all") == 0)
rv = xbps_configure_packages(true);
rv = xbps_configure_packages(&xh, true);
else
rv = xbps_configure_pkg(argv[1], true, false, true);
rv = xbps_configure_pkg(&xh, argv[1], true, false, true);
} else if (strcasecmp(argv[0], "show-deps") == 0) {
/*
@@ -397,7 +395,7 @@ main(int argc, char **argv)
if (argc != 2)
usage(true);
rv = show_pkg_deps(argv[1]);
rv = show_pkg_deps(&xh, argv[1]);
} else if (strcasecmp(argv[0], "list-manual") == 0) {
/*
@@ -407,7 +405,7 @@ main(int argc, char **argv)
if (argc != 1)
usage(true);
rv = xbps_pkgdb_foreach_cb(list_manual_pkgs, NULL);
rv = xbps_pkgdb_foreach_cb(&xh, list_manual_pkgs, NULL);
} else if (strcasecmp(argv[0], "show-revdeps") == 0) {
/*
@@ -416,7 +414,7 @@ main(int argc, char **argv)
if (argc != 2)
usage(true);
rv = show_pkg_reverse_deps(argv[1]);
rv = show_pkg_reverse_deps(&xh, argv[1]);
} else if (strcasecmp(argv[0], "find-files") == 0) {
/*
@@ -426,13 +424,13 @@ main(int argc, char **argv)
if (argc < 2)
usage(true);
rv = find_files_in_packages(argc, argv);
rv = find_files_in_packages(&xh, argc, argv);
} else {
usage(true);
}
out:
xbps_end();
xbps_end(&xh);
exit(rv);
}

View File

@@ -35,7 +35,7 @@
#include "../xbps-repo/defs.h"
int
show_pkg_deps(const char *pkgname)
show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
{
prop_dictionary_t propsd;
int rv = 0;
@@ -45,14 +45,15 @@ show_pkg_deps(const char *pkgname)
/*
* Check for props.plist metadata file.
*/
propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS);
propsd = xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS);
if (propsd == NULL) {
fprintf(stderr,
"%s: unexistent %s metadata file.\n", pkgname,
XBPS_PKGPROPS);
return errno;
}
rv = xbps_callback_array_iter_in_dict(propsd, "run_depends",
rv = xbps_callback_array_iter_in_dict(xhp, propsd, "run_depends",
list_strings_sep_in_array, NULL);
prop_object_release(propsd);
@@ -60,20 +61,20 @@ show_pkg_deps(const char *pkgname)
}
int
show_pkg_reverse_deps(const char *pkgname)
show_pkg_reverse_deps(struct xbps_handle *xhp, const char *pkgname)
{
prop_dictionary_t pkgd;
int rv = 0;
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false);
pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false);
if (pkgd == NULL) {
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (pkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
return 0;
}
}
rv = xbps_callback_array_iter_in_dict(pkgd, "requiredby",
rv = xbps_callback_array_iter_in_dict(xhp, pkgd, "requiredby",
list_strings_sep_in_array, NULL);
prop_object_release(pkgd);

View File

@@ -35,11 +35,13 @@
#include "defs.h"
int
show_pkg_info_from_metadir(const char *pkgname, const char *option)
show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *pkgname,
const char *option)
{
prop_dictionary_t d;
d = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS);
d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS);
if (d == NULL)
return EINVAL;
@@ -53,12 +55,12 @@ show_pkg_info_from_metadir(const char *pkgname, const char *option)
}
int
show_pkg_files_from_metadir(const char *pkgname)
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkgname)
{
prop_dictionary_t d;
int rv = 0;
d = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (d == NULL)
return EINVAL;

View File

@@ -30,14 +30,14 @@
#include "defs.h"
int
show_orphans(void)
show_orphans(struct xbps_handle *xhp)
{
prop_array_t orphans;
prop_object_iterator_t iter;
prop_object_t obj;
const char *pkgver;
orphans = xbps_find_pkg_orphans(NULL);
orphans = xbps_find_pkg_orphans(xhp, NULL);
if (orphans == NULL)
return EINVAL;

View File

@@ -31,9 +31,10 @@
#include "defs.h"
void
state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
state_cb(struct xbps_handle *xhp,
struct xbps_state_cb_data *xscd,
void *cbdata)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd;
const char *version;
bool syslog_enabled = false;
@@ -85,7 +86,8 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
xscd->pkgname, xscd->version);
break;
case XBPS_STATE_UPDATE:
pkgd = xbps_find_pkg_dict_installed(xscd->pkgname, false);
pkgd = xbps_find_pkg_dict_installed(xhp,
xscd->pkgname, false);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
prop_object_release(pkgd);
printf("Updating `%s' (`%s' to `%s') ...\n", xscd->pkgname,
@@ -152,7 +154,8 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
syslog(LOG_ERR, "%s", xscd->desc);
break;
default:
xbps_dbg_printf("unknown state %d\n", xscd->state);
xbps_dbg_printf(xhp,
"unknown state %d\n", xscd->state);
break;
}
}

View File

@@ -97,7 +97,7 @@ show_actions(prop_object_iterator_t iter)
}
static int
show_binpkgs_url(prop_object_iterator_t iter)
show_binpkgs_url(struct xbps_handle *xhp, prop_object_iterator_t iter)
{
prop_object_t obj;
const char *repoloc, *trans;
@@ -117,7 +117,7 @@ show_binpkgs_url(prop_object_iterator_t iter)
if (!xbps_check_is_repository_uri_remote(repoloc))
continue;
binfile = xbps_path_from_repository_uri(obj, repoloc);
binfile = xbps_path_from_repository_uri(xhp, obj, repoloc);
if (binfile == NULL)
return errno;
/*
@@ -226,7 +226,10 @@ show_transaction_sizes(struct transaction *trans)
}
int
dist_upgrade(bool yes, bool dry_run, bool show_download_pkglist_url)
dist_upgrade(struct xbps_handle *xhp,
bool yes,
bool dry_run,
bool show_download_pkglist_url)
{
int rv = 0;
@@ -234,7 +237,7 @@ dist_upgrade(bool yes, bool dry_run, bool show_download_pkglist_url)
* Update all currently installed packages, aka
* "xbps-bin autoupdate".
*/
if ((rv = xbps_transaction_update_packages()) != 0) {
if ((rv = xbps_transaction_update_packages(xhp)) != 0) {
if (rv == ENOENT) {
printf("No packages currently registered.\n");
return 0;
@@ -251,15 +254,15 @@ dist_upgrade(bool yes, bool dry_run, bool show_download_pkglist_url)
return -1;
}
}
return exec_transaction(yes, dry_run, show_download_pkglist_url);
return exec_transaction(xhp, yes, dry_run, show_download_pkglist_url);
}
int
remove_pkg_orphans(bool yes, bool dry_run)
remove_pkg_orphans(struct xbps_handle *xhp, bool yes, bool dry_run)
{
int rv;
if ((rv = xbps_transaction_autoremove_pkgs()) != 0) {
if ((rv = xbps_transaction_autoremove_pkgs(xhp)) != 0) {
if (rv == ENOENT) {
printf("No package orphans were found.\n");
return 0;
@@ -269,15 +272,15 @@ remove_pkg_orphans(bool yes, bool dry_run)
return rv;
}
}
return exec_transaction(yes, dry_run, false);
return exec_transaction(xhp, yes, dry_run, false);
}
int
install_new_pkg(const char *pkg, bool reinstall)
install_new_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
{
int rv;
if ((rv = xbps_transaction_install_pkg(pkg, reinstall)) != 0) {
if ((rv = xbps_transaction_install_pkg(xhp, pkg, reinstall)) != 0) {
if (rv == EEXIST) {
printf("Package `%s' already installed.\n", pkg);
} else if (rv == ENOENT) {
@@ -296,11 +299,11 @@ install_new_pkg(const char *pkg, bool reinstall)
}
int
update_pkg(const char *pkgname)
update_pkg(struct xbps_handle *xhp, const char *pkgname)
{
int rv;
rv = xbps_transaction_update_pkg(pkgname);
rv = xbps_transaction_update_pkg(xhp, pkgname);
if (rv == EEXIST)
printf("Package '%s' is up to date.\n", pkgname);
else if (rv == ENOENT)
@@ -320,7 +323,7 @@ update_pkg(const char *pkgname)
}
int
remove_pkg(const char *pkgname, bool recursive)
remove_pkg(struct xbps_handle *xhp, const char *pkgname, bool recursive)
{
prop_dictionary_t pkgd;
prop_array_t reqby;
@@ -328,10 +331,10 @@ remove_pkg(const char *pkgname, bool recursive)
size_t x;
int rv;
rv = xbps_transaction_remove_pkg(pkgname, recursive);
rv = xbps_transaction_remove_pkg(xhp, pkgname, recursive);
if (rv == EEXIST) {
/* pkg has revdeps */
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
reqby = prop_dictionary_get(pkgd, "requiredby");
prop_object_release(pkgd);
@@ -358,18 +361,20 @@ remove_pkg(const char *pkgname, bool recursive)
}
int
exec_transaction(bool yes, bool dry_run, bool show_download_urls)
exec_transaction(struct xbps_handle *xhp,
bool yes,
bool dry_run,
bool show_download_urls)
{
prop_array_t mdeps, cflicts;
struct transaction *trans;
struct xbps_handle *xhp = xbps_handle_get();
int rv = 0;
trans = calloc(1, sizeof(*trans));
if (trans == NULL)
return ENOMEM;
if ((rv = xbps_transaction_prepare()) != 0) {
if ((rv = xbps_transaction_prepare(xhp)) != 0) {
if (rv == ENODEV) {
mdeps =
prop_dictionary_get(xhp->transd, "missing_deps");
@@ -382,12 +387,13 @@ exec_transaction(bool yes, bool dry_run, bool show_download_urls)
show_conflicts(cflicts);
goto out;
}
xbps_dbg_printf("Empty transaction dictionary: %s\n",
xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n",
strerror(errno));
return rv;
}
xbps_dbg_printf("Dictionary before transaction happens:\n");
xbps_dbg_printf_append("%s", prop_dictionary_externalize(xhp->transd));
xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n");
xbps_dbg_printf_append(xhp, "%s",
prop_dictionary_externalize(xhp->transd));
trans->d = xhp->transd;
trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages");
@@ -408,7 +414,7 @@ exec_transaction(bool yes, bool dry_run, bool show_download_urls)
* Only show URLs to download binary packages.
*/
if (show_download_urls) {
rv = show_binpkgs_url(trans->iter);
rv = show_binpkgs_url(xhp, trans->iter);
goto out;
}
/*
@@ -426,7 +432,7 @@ exec_transaction(bool yes, bool dry_run, bool show_download_urls)
/*
* It's time to run the transaction!
*/
if ((rv = xbps_transaction_commit()) == 0) {
if ((rv = xbps_transaction_commit(xhp)) == 0) {
printf("\nxbps-bin: %u installed, %u updated, "
"%u configured, %u removed.\n", trans->inst_pkgcnt,
trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,

View File

@@ -30,8 +30,11 @@
#include "defs.h"
void
unpack_progress_cb_verbose(const struct xbps_unpack_cb_data *xpd, void *cbdata)
unpack_progress_cb_verbose(struct xbps_handle *xhp,
struct xbps_unpack_cb_data *xpd,
void *cbdata)
{
(void)xhp;
(void)cbdata;
if (xpd->entry == NULL || xpd->entry_total_count <= 0)
@@ -44,8 +47,11 @@ unpack_progress_cb_verbose(const struct xbps_unpack_cb_data *xpd, void *cbdata)
}
void
unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata)
unpack_progress_cb(struct xbps_handle *xhp,
struct xbps_unpack_cb_data *xpd,
void *cbdata)
{
(void)xhp;
(void)cbdata;
if (xpd->entry_total_count <= 0)

View File

@@ -166,11 +166,15 @@ show_pkg_files(prop_dictionary_t filesd)
}
static int
_find_longest_pkgver_cb(prop_object_t obj, void *arg, bool *loop_done)
_find_longest_pkgver_cb(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
size_t *len = arg;
const char *pkgver;
(void)xhp;
(void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
@@ -181,25 +185,29 @@ _find_longest_pkgver_cb(prop_object_t obj, void *arg, bool *loop_done)
}
size_t
find_longest_pkgver(prop_object_t o)
find_longest_pkgver(struct xbps_handle *xhp, prop_object_t o)
{
size_t len = 0;
if (prop_object_type(o) == PROP_TYPE_ARRAY)
(void)xbps_callback_array_iter(o,
(void)xbps_callback_array_iter(xhp, o,
_find_longest_pkgver_cb, &len);
else
(void)xbps_pkgdb_foreach_cb(
(void)xbps_pkgdb_foreach_cb(xhp,
_find_longest_pkgver_cb, &len);
return len;
}
int
list_strings_sep_in_array(prop_object_t obj, void *arg, bool *loop_done)
list_strings_sep_in_array(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
const char *sep = arg;
(void)xhp;
(void)loop_done;
printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj));

View File

@@ -94,7 +94,6 @@ die(const char *fmt, ...)
vfprintf(stderr, fmt, ap);
fprintf(stderr, " (%s)\n", strerror(save_errno));
va_end(ap);
xbps_end();
exit(EXIT_FAILURE);
}
@@ -357,7 +356,8 @@ parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd,
}
static void
create_dot_graph(FILE *f,
create_dot_graph(struct xbps_handle *xhp,
FILE *f,
prop_dictionary_t plistd,
prop_dictionary_t confd,
bool revdeps)
@@ -422,7 +422,7 @@ create_dot_graph(FILE *f,
* list file, aka XBPS_META_PATH/XBPS_PKGDB.
*/
if (revdeps) {
regpkgd = xbps_find_pkg_dict_installed(pkgn, false);
regpkgd = xbps_find_pkg_dict_installed(xhp, pkgn, false);
if (regpkgd == NULL)
die("cannot find '%s' dictionary on %s!",
pkgn, XBPS_PKGDB);
@@ -515,7 +515,7 @@ main(int argc, char **argv)
/*
* Internalize the plist file of the target installed package.
*/
plistd = xbps_dictionary_from_metadata_plist(argv[0], XBPS_PKGPROPS);
plistd = xbps_dictionary_from_metadata_plist(&xh, argv[0], XBPS_PKGPROPS);
if (plistd == NULL)
die("cannot internalize %s from %s", XBPS_PKGPROPS, argv[0]);
@@ -528,10 +528,11 @@ main(int argc, char **argv)
/*
* Create the dot(1) graph!
*/
create_dot_graph(f, plistd, confd, revdeps);
create_dot_graph(&xh, f, plistd, confd, revdeps);
prop_object_release(plistd);
prop_object_release(confd);
xbps_end(&xh);
exit(EXIT_SUCCESS);
}

View File

@@ -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);

View File

@@ -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_ */

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -60,7 +60,6 @@ write_plist_file(prop_dictionary_t dict, const char *file)
static void __attribute__((noreturn))
usage(void)
{
xbps_end();
fprintf(stderr,
"usage: xbps-uhelper [options] [action] [args]\n"
"\n"
@@ -192,7 +191,7 @@ main(int argc, char **argv)
assert(tmp != NULL);
prop_dictionary_set_cstring_nocopy(dict, "pkgver", tmp);
pkgd = xbps_pkgdb_get_pkgd(argv[1], false);
pkgd = xbps_pkgdb_get_pkgd(&xh, argv[1], false);
if (pkgd != NULL) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgn);
@@ -204,12 +203,12 @@ main(int argc, char **argv)
in_chroot ? "[chroot] " : "",
pkgn, version, MSG_RESET);
} else {
rv = xbps_set_pkg_state_installed(argv[1], argv[2],
rv = xbps_set_pkg_state_installed(&xh, argv[1], argv[2],
XBPS_PKG_STATE_INSTALLED);
if (rv != 0)
goto out;
rv = xbps_register_pkg(dict, true);
rv = xbps_register_pkg(&xh, dict, true);
if (rv != 0) {
fprintf(stderr, "%s%s=> couldn't register %s-%s "
"(%s).%s\n", MSG_ERROR,
@@ -227,7 +226,7 @@ main(int argc, char **argv)
if (argc != 3)
usage();
rv = xbps_unregister_pkg(argv[1], argv[2], true);
rv = xbps_unregister_pkg(&xh, argv[1], argv[2], true);
if (rv == ENOENT) {
fprintf(stderr, "%s=> ERROR: %s not registered "
"in database.%s\n", MSG_WARN, argv[1], MSG_RESET);
@@ -245,7 +244,7 @@ main(int argc, char **argv)
if (argc != 2)
usage();
dict = xbps_pkgdb_get_pkgd(argv[1], false);
dict = xbps_pkgdb_get_pkgd(&xh, argv[1], false);
if (dict == NULL) {
rv = errno;
goto out;
@@ -356,7 +355,7 @@ main(int argc, char **argv)
usage();
for (i = 1; i < argc; i++) {
rv = xbps_fetch_file(argv[i], ".", false, "v");
rv = xbps_fetch_file(&xh, argv[i], ".", false, "v");
if (rv == -1) {
printf("%s: %s\n", argv[1],
xbps_fetch_error_string());
@@ -385,7 +384,7 @@ main(int argc, char **argv)
}
xh.pkgdb = prop_array_copy(array);
prop_object_release(dict);
rv = xbps_pkgdb_update(true);
rv = xbps_pkgdb_update(&xh, true);
if (rv == 0) {
printf("Migrated regpkgdb to pkgdb "
"successfully.\n");
@@ -398,6 +397,6 @@ main(int argc, char **argv)
usage();
}
out:
xbps_end();
xbps_end(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
}