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

View File

@ -47,12 +47,16 @@
* Returns 0 if test ran successfully, 1 otherwise and -1 on error. * Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int 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_dictionary_t pkgd = arg;
prop_array_t reqby; prop_array_t reqby;
bool autoinst = false; bool autoinst = false;
(void)xhp;
/* /*
* Check if package has been installed manually but any other * Check if package has been installed manually but any other
* package is currently depending on it; in that case the package * 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. * Return 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int 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_array_t array;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;

View File

@ -43,7 +43,10 @@ struct check_reqby_data {
}; };
static int 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; struct check_reqby_data *crd = arg;
prop_array_t curpkg_rdeps, provides; 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. * installed metadata directory.
*/ */
curpkg_propsd = curpkg_propsd =
xbps_dictionary_from_metadata_plist(curpkgn, XBPS_PKGPROPS); xbps_dictionary_from_metadata_plist(xhp, curpkgn, XBPS_PKGPROPS);
if (curpkg_propsd == NULL) { if (curpkg_propsd == NULL) {
xbps_error_printf("%s: missing %s metadata file!\n", xbps_error_printf("%s: missing %s metadata file!\n",
curpkgn, XBPS_PKGPROPS); 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. * Removes unused entries in pkg's requiredby array.
*/ */
static bool 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_array_t reqby;
prop_dictionary_t pkgd; 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++) { for (i = 0; i < prop_array_count(reqby); i++) {
prop_array_get_cstring_nocopy(reqby, i, &str); 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); prop_object_release(pkgd);
continue; 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. * Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int 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; prop_dictionary_t pkgd = arg;
struct check_reqby_data crd; 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); prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &crd.pkgver);
/* missing reqby entries in pkgs */ /* 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) { if (rv < 0) {
return rv; return rv;
} else if (rv == 1) { } 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); printf("%s: requiredby fix done!\n\n", crd.pkgver);
} }
/* remove stale entries in pkg's reqby */ /* 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; *pkgdb_update = true;
return 0; return 0;

View File

@ -45,7 +45,10 @@
*/ */
int 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_dictionary_t pkg_propsd = arg;
prop_object_t obj; prop_object_t obj;
@ -68,7 +71,7 @@ check_pkg_rundeps(const char *pkgname, void *arg, bool *pkgdb_update)
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
return -1; 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", xbps_error_printf("%s: dependency not satisfied: %s\n",
pkgname, reqpkg); pkgname, reqpkg);
test_broken = true; test_broken = true;

View File

@ -45,9 +45,11 @@
* returns 0 if test ran successfully, 1 otherwise and -1 on error. * returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int 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_array_t array;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;

View File

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

View File

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

View File

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

View File

@ -33,7 +33,10 @@
#include "compat.h" #include "compat.h"
int 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; struct list_pkgver_cb *lpc = arg;
const char *pkgver, *short_desc, *arch; 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; size_t i = 0;
bool chkarch; bool chkarch;
(void)xhp;
(void)loop_done; (void)loop_done;
chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); 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 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; const char *pkgver;
bool automatic = false; bool automatic = false;
(void)xhp;
(void)arg; (void)arg;
(void)loop_done; (void)loop_done;

View File

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

View File

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

View File

@ -35,11 +35,13 @@
#include "defs.h" #include "defs.h"
int 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; 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) if (d == NULL)
return EINVAL; return EINVAL;
@ -53,12 +55,12 @@ show_pkg_info_from_metadir(const char *pkgname, const char *option)
} }
int 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; prop_dictionary_t d;
int rv = 0; 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) if (d == NULL)
return EINVAL; return EINVAL;

View File

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

View File

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

View File

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

View File

@ -30,8 +30,11 @@
#include "defs.h" #include "defs.h"
void 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; (void)cbdata;
if (xpd->entry == NULL || xpd->entry_total_count <= 0) 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 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; (void)cbdata;
if (xpd->entry_total_count <= 0) if (xpd->entry_total_count <= 0)

View File

@ -166,11 +166,15 @@ show_pkg_files(prop_dictionary_t filesd)
} }
static int 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; size_t *len = arg;
const char *pkgver; const char *pkgver;
(void)xhp;
(void)loop_done; (void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); 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 size_t
find_longest_pkgver(prop_object_t o) find_longest_pkgver(struct xbps_handle *xhp, prop_object_t o)
{ {
size_t len = 0; size_t len = 0;
if (prop_object_type(o) == PROP_TYPE_ARRAY) 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); _find_longest_pkgver_cb, &len);
else else
(void)xbps_pkgdb_foreach_cb( (void)xbps_pkgdb_foreach_cb(xhp,
_find_longest_pkgver_cb, &len); _find_longest_pkgver_cb, &len);
return len; return len;
} }
int 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; const char *sep = arg;
(void)xhp;
(void)loop_done; (void)loop_done;
printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj)); 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); vfprintf(stderr, fmt, ap);
fprintf(stderr, " (%s)\n", strerror(save_errno)); fprintf(stderr, " (%s)\n", strerror(save_errno));
va_end(ap); va_end(ap);
xbps_end();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -357,7 +356,8 @@ parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd,
} }
static void static void
create_dot_graph(FILE *f, create_dot_graph(struct xbps_handle *xhp,
FILE *f,
prop_dictionary_t plistd, prop_dictionary_t plistd,
prop_dictionary_t confd, prop_dictionary_t confd,
bool revdeps) bool revdeps)
@ -422,7 +422,7 @@ create_dot_graph(FILE *f,
* list file, aka XBPS_META_PATH/XBPS_PKGDB. * list file, aka XBPS_META_PATH/XBPS_PKGDB.
*/ */
if (revdeps) { if (revdeps) {
regpkgd = xbps_find_pkg_dict_installed(pkgn, false); regpkgd = xbps_find_pkg_dict_installed(xhp, pkgn, false);
if (regpkgd == NULL) if (regpkgd == NULL)
die("cannot find '%s' dictionary on %s!", die("cannot find '%s' dictionary on %s!",
pkgn, XBPS_PKGDB); pkgn, XBPS_PKGDB);
@ -515,7 +515,7 @@ main(int argc, char **argv)
/* /*
* Internalize the plist file of the target installed package. * 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) if (plistd == NULL)
die("cannot internalize %s from %s", XBPS_PKGPROPS, argv[0]); 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 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(plistd);
prop_object_release(confd); prop_object_release(confd);
xbps_end(&xh);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -34,10 +34,9 @@
#include "defs.h" #include "defs.h"
int int
cachedir_clean(void) cachedir_clean(struct xbps_handle *xhp)
{ {
prop_dictionary_t pkg_propsd, repo_pkgd; prop_dictionary_t pkg_propsd, repo_pkgd;
struct xbps_handle *xhp = xbps_handle_get();
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
const char *pkgver, *rsha256; const char *pkgver, *rsha256;
@ -78,7 +77,7 @@ cachedir_clean(void)
* Remove binary pkg if it's not registered in any repository * Remove binary pkg if it's not registered in any repository
* or if hash doesn't match. * 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) { if (repo_pkgd) {
prop_dictionary_get_cstring_nocopy(repo_pkgd, prop_dictionary_get_cstring_nocopy(repo_pkgd,
"filename-sha256", &rsha256); "filename-sha256", &rsha256);

View File

@ -35,25 +35,36 @@ struct repo_search_data {
}; };
/* From index.c */ /* From index.c */
int repo_genindex(const char *); int repo_genindex(struct xbps_handle *, const char *);
/* From index-files.c */ /* From index-files.c */
int repo_genindex_files(const char *); int repo_genindex_files(struct xbps_handle *, const char *);
/* From find-files.c */ /* 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 */ /* From list.c */
int repo_pkg_list_cb(struct xbps_rpool_index *, void *, bool *); int repo_pkg_list_cb(struct xbps_handle *,
int repo_list_uri_cb(struct xbps_rpool_index *, void *, bool *); struct xbps_rpool_index *,
int repo_search_pkgs_cb(struct xbps_rpool_index *, void *, bool *); 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 */ /* From show.c */
int show_pkg_info_from_repolist(const char *, const char *); int show_pkg_info_from_repolist(struct xbps_handle *,
int show_pkg_deps_from_repolist(const char *); const char *,
int show_pkg_namedesc(prop_object_t, void *, bool *); 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 */ /* From clean.c */
int cachedir_clean(void); int cachedir_clean(struct xbps_handle *);
#endif /* !_XBPS_REPO_DEFS_H_ */ #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 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; prop_array_t idxfiles;
struct ffdata *ffd = arg; struct ffdata *ffd = arg;
@ -75,7 +78,7 @@ find_files_in_package(struct xbps_rpool_index *rpi, void *arg, bool *done)
(void)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; return ENOMEM;
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) { 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 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; struct ffdata ffd;
ffd.npatterns = npatterns; ffd.npatterns = npatterns;
ffd.patterns = patterns; 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 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; struct index_files_data *ifd = arg;
const char *pkgver, *arch; const char *pkgver, *arch;
char *str; char *str;
(void)xhp;
(void)done; (void)done;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); 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 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_object_t obj2, fileobj;
prop_dictionary_t pkg_filesd, pkgd; prop_dictionary_t pkg_filesd, pkgd;
@ -81,6 +88,7 @@ genindex_files_cb(prop_object_t obj, void *arg, bool *done)
bool found = false; bool found = false;
size_t i; size_t i;
(void)xhp;
(void)done; (void)done;
prop_dictionary_get_cstring_nocopy(obj, "filename", &binpkg); 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. * Create the index files cache for all packages in repository.
*/ */
int int
repo_genindex_files(const char *pkgdir) repo_genindex_files(struct xbps_handle *xhp, const char *pkgdir)
{ {
prop_array_t idx; prop_array_t idx;
struct index_files_data *ifd = NULL; struct index_files_data *ifd = NULL;
@ -220,7 +228,7 @@ repo_genindex_files(const char *pkgdir)
char *plist, *pkgver; char *plist, *pkgver;
int rv; int rv;
plist = xbps_pkg_index_plist(pkgdir); plist = xbps_pkg_index_plist(xhp, pkgdir);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;
@ -233,7 +241,7 @@ repo_genindex_files(const char *pkgdir)
free(plist); free(plist);
/* internalize repository index-files plist (if exists) */ /* 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) { if (plist == NULL) {
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;
@ -255,7 +263,7 @@ repo_genindex_files(const char *pkgdir)
/* remove obsolete pkg entries */ /* remove obsolete pkg entries */
if (!ifd->new) { if (!ifd->new) {
rv = xbps_callback_array_iter(ifd->idxfiles, rv = xbps_callback_array_iter(xhp, ifd->idxfiles,
rmobsoletes_files_cb, ifd); rmobsoletes_files_cb, ifd);
if (rv != 0) if (rv != 0)
goto out; goto out;
@ -281,7 +289,7 @@ repo_genindex_files(const char *pkgdir)
} }
} }
/* iterate over index.plist array */ /* 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; goto out;
if (!ifd->flush) 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). * binary package cannot be read (unavailable, not enough perms, etc).
*/ */
static int 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_array_t array;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
@ -57,7 +57,7 @@ remove_missing_binpkg_entries(const char *repodir)
int rv = 0; int rv = 0;
bool found = false; bool found = false;
plist = xbps_pkg_index_plist(repodir); plist = xbps_pkg_index_plist(xhp, repodir);
if (plist == NULL) if (plist == NULL)
return -1; return -1;
@ -104,7 +104,7 @@ again:
} }
static prop_array_t static prop_array_t
repoidx_get(const char *pkgdir) repoidx_get(struct xbps_handle *xhp, const char *pkgdir)
{ {
prop_array_t array; prop_array_t array;
char *plist; char *plist;
@ -113,10 +113,10 @@ repoidx_get(const char *pkgdir)
* Remove entries in repositories index for unexistent * Remove entries in repositories index for unexistent
* packages, i.e dangling entries. * packages, i.e dangling entries.
*/ */
if ((rv = remove_missing_binpkg_entries(pkgdir)) != 0) if ((rv = remove_missing_binpkg_entries(xhp, pkgdir)) != 0)
return NULL; return NULL;
plist = xbps_pkg_index_plist(pkgdir); plist = xbps_pkg_index_plist(xhp, pkgdir);
if (plist == NULL) if (plist == NULL)
return NULL; return NULL;
@ -297,7 +297,7 @@ out:
} }
int int
repo_genindex(const char *pkgdir) repo_genindex(struct xbps_handle *xhp, const char *pkgdir)
{ {
prop_array_t idx = NULL; prop_array_t idx = NULL;
struct dirent *dp; struct dirent *dp;
@ -311,11 +311,11 @@ repo_genindex(const char *pkgdir)
/* /*
* Create or read existing package index plist file. * Create or read existing package index plist file.
*/ */
idx = repoidx_get(pkgdir); idx = repoidx_get(xhp, pkgdir);
if (idx == NULL) if (idx == NULL)
return errno; return errno;
plist = xbps_pkg_index_plist(pkgdir); plist = xbps_pkg_index_plist(xhp, pkgdir);
if (plist == NULL) { if (plist == NULL) {
prop_object_release(idx); prop_object_release(idx);
return errno; return errno;

View File

@ -35,7 +35,10 @@
#include "../xbps-bin/defs.h" #include "../xbps-bin/defs.h"
int 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; struct list_pkgver_cb lpc;
const char *repo = arg; 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.check_state = false;
lpc.state = 0; lpc.state = 0;
lpc.pkgver_len = find_longest_pkgver(rpi->repo); lpc.pkgver_len = find_longest_pkgver(xhp, rpi->repo);
if (arg == NULL) if (arg == NULL)
printf("From %s repository ...\n", rpi->uri); 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; return 0;
} }
int 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)arg;
(void)done; (void)done;
@ -68,14 +75,17 @@ repo_list_uri_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
} }
int 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; struct repo_search_data *rsd = arg;
(void)done; (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); 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; return 0;
} }

View File

@ -41,7 +41,6 @@
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(bool fail) usage(bool fail)
{ {
xbps_end();
fprintf(stderr, fprintf(stderr,
"Usage: xbps-repo [options] target [arguments]\n\n" "Usage: xbps-repo [options] target [arguments]\n\n"
"[options]\n" "[options]\n"
@ -151,7 +150,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(true); usage(true);
rv = xbps_rpool_foreach(repo_list_uri_cb, NULL); rv = xbps_rpool_foreach(&xh, repo_list_uri_cb, NULL);
if (rv == ENOTSUP) if (rv == ENOTSUP)
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n"); "currently registered!\n");
@ -165,7 +164,7 @@ main(int argc, char **argv)
if (argc < 1 || argc > 2) if (argc < 1 || argc > 2)
usage(true); 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) if (rv == ENOTSUP)
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n"); "currently registered!\n");
@ -187,7 +186,7 @@ main(int argc, char **argv)
} }
rsd->npatterns = argc; rsd->npatterns = argc;
rsd->patterns = argv; rsd->patterns = argv;
rv = xbps_rpool_foreach(repo_search_pkgs_cb, rsd); rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, rsd);
free(rsd); free(rsd);
if (rv == ENOTSUP) if (rv == ENOTSUP)
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
@ -200,7 +199,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(true); usage(true);
rv = show_pkg_info_from_repolist(argv[1], option); rv = show_pkg_info_from_repolist(&xh, argv[1], option);
if (rv == ENOENT) { if (rv == ENOENT) {
xbps_error_printf("Unable to locate package " xbps_error_printf("Unable to locate package "
"`%s' in repository pool.\n", argv[1]); "`%s' in repository pool.\n", argv[1]);
@ -216,7 +215,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(true); usage(true);
rv = show_pkg_deps_from_repolist(argv[1]); rv = show_pkg_deps_from_repolist(&xh, argv[1]);
if (rv == ENOENT) { if (rv == ENOENT) {
xbps_error_printf("Unable to locate package " xbps_error_printf("Unable to locate package "
"`%s' in repository pool.\n", argv[1]); "`%s' in repository pool.\n", argv[1]);
@ -232,7 +231,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(true); usage(true);
pkgd = xbps_rpool_dictionary_metadata_plist(argv[1], pkgd = xbps_rpool_dictionary_metadata_plist(&xh, argv[1],
"./files.plist"); "./files.plist");
if (pkgd == NULL) { if (pkgd == NULL) {
if (errno == ENOTSUP) { if (errno == ENOTSUP) {
@ -256,7 +255,7 @@ main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(true); usage(true);
rv = repo_find_files_in_packages(argc, argv); rv = repo_find_files_in_packages(&xh, argc, argv);
if (rv == ENOTSUP) { if (rv == ENOTSUP) {
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n"); "currently registered!\n");
@ -266,16 +265,16 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(true); usage(true);
rv = repo_genindex(argv[1]); rv = repo_genindex(&xh, argv[1]);
if (rv == 0) if (rv == 0)
rv = repo_genindex_files(argv[1]); rv = repo_genindex_files(&xh, argv[1]);
} 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 || argc > 2) if (argc < 1 || argc > 2)
usage(true); usage(true);
rv = xbps_rpool_sync(argv[1]); rv = xbps_rpool_sync(&xh, argv[1]);
if (rv == ENOTSUP) { if (rv == ENOTSUP) {
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n"); "currently registered!\n");
@ -285,12 +284,12 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(true); usage(true);
rv = cachedir_clean(); rv = cachedir_clean(&xh);
} else { } else {
usage(true); usage(true);
} }
out: out:
xbps_end(); xbps_end(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -44,14 +44,16 @@
#include "defs.h" #include "defs.h"
int 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; prop_dictionary_t pkgd;
if (xbps_pkgpattern_version(pattern)) if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(pattern, true, false); pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else else
pkgd = xbps_rpool_find_pkg(pattern, false, true); pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
if (pkgd == NULL) if (pkgd == NULL)
return errno; return errno;
@ -67,15 +69,15 @@ show_pkg_info_from_repolist(const char *pattern, const char *option)
} }
int 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; prop_dictionary_t pkgd;
const char *ver, *repoloc; const char *ver, *repoloc;
if (xbps_pkgpattern_version(pattern)) if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(pattern, true, false); pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else else
pkgd = xbps_rpool_find_pkg(pattern, false, true); pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
if (pkgd == NULL) if (pkgd == NULL)
return errno; return errno;
@ -84,7 +86,7 @@ show_pkg_deps_from_repolist(const char *pattern)
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
printf("Repository %s [pkgver: %s]\n", repoloc, ver); 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); "run_depends", list_strings_sep_in_array, NULL);
prop_object_release(pkgd); prop_object_release(pkgd);
@ -92,13 +94,17 @@ show_pkg_deps_from_repolist(const char *pattern)
} }
int 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; struct repo_search_data *rsd = arg;
const char *pkgver, *pkgname, *desc, *arch; const char *pkgver, *pkgname, *desc, *arch;
char *tmp = NULL; char *tmp = NULL;
size_t i, x; size_t i, x;
(void)xhp;
(void)loop_done; (void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); 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)) static void __attribute__((noreturn))
usage(void) usage(void)
{ {
xbps_end();
fprintf(stderr, fprintf(stderr,
"usage: xbps-uhelper [options] [action] [args]\n" "usage: xbps-uhelper [options] [action] [args]\n"
"\n" "\n"
@ -192,7 +191,7 @@ main(int argc, char **argv)
assert(tmp != NULL); assert(tmp != NULL);
prop_dictionary_set_cstring_nocopy(dict, "pkgver", tmp); 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) { if (pkgd != NULL) {
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgn); "pkgname", &pkgn);
@ -204,12 +203,12 @@ main(int argc, char **argv)
in_chroot ? "[chroot] " : "", in_chroot ? "[chroot] " : "",
pkgn, version, MSG_RESET); pkgn, version, MSG_RESET);
} else { } 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); XBPS_PKG_STATE_INSTALLED);
if (rv != 0) if (rv != 0)
goto out; goto out;
rv = xbps_register_pkg(dict, true); rv = xbps_register_pkg(&xh, dict, true);
if (rv != 0) { if (rv != 0) {
fprintf(stderr, "%s%s=> couldn't register %s-%s " fprintf(stderr, "%s%s=> couldn't register %s-%s "
"(%s).%s\n", MSG_ERROR, "(%s).%s\n", MSG_ERROR,
@ -227,7 +226,7 @@ main(int argc, char **argv)
if (argc != 3) if (argc != 3)
usage(); usage();
rv = xbps_unregister_pkg(argv[1], argv[2], true); rv = xbps_unregister_pkg(&xh, argv[1], argv[2], true);
if (rv == ENOENT) { if (rv == ENOENT) {
fprintf(stderr, "%s=> ERROR: %s not registered " fprintf(stderr, "%s=> ERROR: %s not registered "
"in database.%s\n", MSG_WARN, argv[1], MSG_RESET); "in database.%s\n", MSG_WARN, argv[1], MSG_RESET);
@ -245,7 +244,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
dict = xbps_pkgdb_get_pkgd(argv[1], false); dict = xbps_pkgdb_get_pkgd(&xh, argv[1], false);
if (dict == NULL) { if (dict == NULL) {
rv = errno; rv = errno;
goto out; goto out;
@ -356,7 +355,7 @@ main(int argc, char **argv)
usage(); usage();
for (i = 1; i < argc; i++) { 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) { if (rv == -1) {
printf("%s: %s\n", argv[1], printf("%s: %s\n", argv[1],
xbps_fetch_error_string()); xbps_fetch_error_string());
@ -385,7 +384,7 @@ main(int argc, char **argv)
} }
xh.pkgdb = prop_array_copy(array); xh.pkgdb = prop_array_copy(array);
prop_object_release(dict); prop_object_release(dict);
rv = xbps_pkgdb_update(true); rv = xbps_pkgdb_update(&xh, true);
if (rv == 0) { if (rv == 0) {
printf("Migrated regpkgdb to pkgdb " printf("Migrated regpkgdb to pkgdb "
"successfully.\n"); "successfully.\n");
@ -398,6 +397,6 @@ main(int argc, char **argv)
usage(); usage();
} }
out: out:
xbps_end(); xbps_end(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120611" #define XBPS_API_VERSION "20120614"
#define XBPS_VERSION "0.16" #define XBPS_VERSION "0.16"
/** /**
@ -201,11 +201,6 @@
__BEGIN_DECLS __BEGIN_DECLS
void xbps_dbg_printf(const char *, ...);
void xbps_dbg_printf_append(const char *, ...);
void xbps_error_printf(const char *, ...);
void xbps_warn_printf(const char *, ...);
/** @addtogroup initend */ /** @addtogroup initend */
/*@{*/ /*@{*/
@ -478,7 +473,7 @@ struct xbps_handle {
* Pointer to the supplifed function callback to be used * Pointer to the supplifed function callback to be used
* in the XBPS possible states. * in the XBPS possible states.
*/ */
void (*state_cb)(const struct xbps_state_cb_data *, void *); void (*state_cb)(struct xbps_handle *, struct xbps_state_cb_data *, void *);
/** /**
* Pointer to user supplied data to be passed as argument to * Pointer to user supplied data to be passed as argument to
* the \a xbps_state_cb function callback. * the \a xbps_state_cb function callback.
@ -488,7 +483,7 @@ struct xbps_handle {
* Pointer to the supplied function callback to be used in * Pointer to the supplied function callback to be used in
* xbps_unpack_binary_pkg(). * xbps_unpack_binary_pkg().
*/ */
void (*unpack_cb)(const struct xbps_unpack_cb_data *, void *); void (*unpack_cb)(struct xbps_handle *, struct xbps_unpack_cb_data *, void *);
/** /**
* Pointer to user supplied data to be passed as argument to * Pointer to user supplied data to be passed as argument to
* the \a xbps_unpack_cb function callback. * the \a xbps_unpack_cb function callback.
@ -498,7 +493,7 @@ struct xbps_handle {
* Pointer to the supplied function callback to be used in * Pointer to the supplied function callback to be used in
* xbps_fetch_file(). * xbps_fetch_file().
*/ */
void (*fetch_cb)(const struct xbps_fetch_cb_data *, void *); void (*fetch_cb)(struct xbps_handle *, struct xbps_fetch_cb_data *, void *);
/** /**
* @var fetch_cb_data * @var fetch_cb_data
* *
@ -568,6 +563,11 @@ struct xbps_handle {
int flags; int flags;
}; };
void xbps_dbg_printf(struct xbps_handle *, const char *, ...);
void xbps_dbg_printf_append(struct xbps_handle *, const char *, ...);
void xbps_error_printf(const char *, ...);
void xbps_warn_printf(const char *, ...);
/** /**
* Initialize the XBPS library with the following steps: * Initialize the XBPS library with the following steps:
* *
@ -584,15 +584,10 @@ int xbps_init(struct xbps_handle *xhp);
/** /**
* Releases all resources used by libxbps. * Releases all resources used by libxbps.
*/
void xbps_end(void);
/**
* Returns a pointer to the xbps_handle structure passed to xbps_init().
* *
* @return A pointer the struct xbps_handle passed to xbps_init(). * @param[in] xhp Pointer to an xbps_handle strcucture.
*/ */
struct xbps_handle *xbps_handle_get(void); void xbps_end(struct xbps_handle *xhp);
/*@}*/ /*@}*/
@ -602,6 +597,7 @@ struct xbps_handle *xbps_handle_get(void);
/** /**
* Configure (or force reconfiguration of) a package. * Configure (or force reconfiguration of) a package.
* *
* @param[in] xhp Pointer to an xbps_handle strcucture.
* @param[in] pkgname Package name to configure. * @param[in] pkgname Package name to configure.
* @param[in] check_state Set it to true to check that package is * @param[in] check_state Set it to true to check that package is
* in unpacked state. * in unpacked state.
@ -610,18 +606,21 @@ struct xbps_handle *xbps_handle_get(void);
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_configure_pkg(const char *pkgname, int xbps_configure_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool check_state, bool check_state,
bool update, bool update,
bool flush); bool flush);
/** /**
* Configure (or force reconfiguration of) all packages. * Configure (or force reconfiguration of) all packages.
*
* @param[in] xhp Pointer to an xbps_handle strcucture.
* @param[in] flush Set it to true to flush state to pkgdb. * @param[in] flush Set it to true to flush state to pkgdb.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_configure_packages(bool flush); int xbps_configure_packages(struct xbps_handle *xhp, bool flush);
/*@}*/ /*@}*/
@ -632,6 +631,7 @@ int xbps_configure_packages(bool flush);
/** /**
* Download a file from a remote URL. * Download a file from a remote URL.
* *
* @param[in] xhp Pointer to an xbps_handle strcucture.
* @param[in] uri Remote URI string. * @param[in] uri Remote URI string.
* @param[in] outputdir Directory string to store downloaded file. * @param[in] outputdir Directory string to store downloaded file.
* @param[in] refetch If true and local/remote size/mtime do not match, * @param[in] refetch If true and local/remote size/mtime do not match,
@ -641,7 +641,8 @@ int xbps_configure_packages(bool flush);
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime * @return -1 on error, 0 if not downloaded (because local/remote size/mtime
* do not match) and 1 if downloaded successfully. * do not match) and 1 if downloaded successfully.
**/ **/
int xbps_fetch_file(const char *uri, int xbps_fetch_file(struct xbps_handle *xhp,
const char *uri,
const char *outputdir, const char *outputdir,
bool refetch, bool refetch,
const char *flags); const char *flags);
@ -660,13 +661,14 @@ const char *xbps_fetch_error_string(void);
* *
* Finds all package orphans currently installed. * Finds all package orphans currently installed.
* *
* @param[in] xhp Pointer to an xbps_handle strcucture.
* @param[in] orphans Proplib array of strings with package names of * @param[in] orphans Proplib array of strings with package names of
* packages that should be treated as they were already removed (optional). * packages that should be treated as they were already removed (optional).
* *
* @return A proplib array of dictionaries with all orphans found, * @return A proplib array of dictionaries with all orphans found,
* on error NULL is returned and errno is set appropiately. * on error NULL is returned and errno is set appropiately.
*/ */
prop_array_t xbps_find_pkg_orphans(prop_array_t orphans); prop_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, prop_array_t orphans);
/** @addtogroup pkgdb */ /** @addtogroup pkgdb */
/*@{*/ /*@{*/
@ -675,19 +677,22 @@ prop_array_t xbps_find_pkg_orphans(prop_array_t orphans);
* Executes a function callback per a package dictionary registered * Executes a function callback per a package dictionary registered
* in master package database (pkgdb) plist (downwards). * in master package database (pkgdb) plist (downwards).
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] fn Function callback to run for any pkg dictionary. * @param[in] fn Function callback to run for any pkg dictionary.
* @param[in] arg Argument to be passed to the function callback. * @param[in] arg Argument to be passed to the function callback.
* *
* @return 0 on success (all objects were processed), otherwise * @return 0 on success (all objects were processed), otherwise
* the value returned by the function callback. * the value returned by the function callback.
*/ */
int xbps_pkgdb_foreach_cb(int (*fn)(prop_object_t, void *, bool *), int xbps_pkgdb_foreach_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
* Executes a function callback per a package dictionary registered * Executes a function callback per a package dictionary registered
* in master package database (pkgdb) plist, in reverse order (upwards). * in master package database (pkgdb) plist, in reverse order (upwards).
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] fn Function callback to run for any pkg dictionary. * @param[in] fn Function callback to run for any pkg dictionary.
* @param[in] arg Argument to be passed to the function callback. * @param[in] arg Argument to be passed to the function callback.
* *
@ -695,13 +700,15 @@ int xbps_pkgdb_foreach_cb(int (*fn)(prop_object_t, void *, bool *),
* the value returned by the funcion callback. * the value returned by the funcion callback.
*/ */
int xbps_pkgdb_foreach_reverse_cb( int xbps_pkgdb_foreach_reverse_cb(
int (*fn)(prop_object_t, void *, bool *), struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
* Returns a package dictionary from master package database (pkgdb) plist, * Returns a package dictionary from master package database (pkgdb) plist,
* matching pkgname or pkgver object in \a pkg. * matching pkgname or pkgver object in \a pkg.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkg Package name or name-version to match. * @param[in] pkg Package name or name-version to match.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
* package pattern, i.e `foo>=0' or `foo<1'. * package pattern, i.e `foo>=0' or `foo<1'.
@ -710,24 +717,29 @@ int xbps_pkgdb_foreach_reverse_cb(
* with \a prop_dictionary_copy() so it must be released when not required * with \a prop_dictionary_copy() so it must be released when not required
* anymore with prop_object_release(). NULL otherwise. * anymore with prop_object_release(). NULL otherwise.
*/ */
prop_dictionary_t xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern); prop_dictionary_t xbps_pkgdb_get_pkgd(struct xbps_handle *xhp,
const char *pkg,
bool bypattern);
/** /**
* Returns a package dictionary from master package database (pkgdb) plist, * Returns a package dictionary from master package database (pkgdb) plist,
* matching the pkgver object in \a pkg dictionary. * matching the pkgver object in \a pkg dictionary.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgver Package name-version to match, i.e 'foo-1.0'. * @param[in] pkgver Package name-version to match, i.e 'foo-1.0'.
* *
* @return The matching proplib package dictionary from pkgdb copied * @return The matching proplib package dictionary from pkgdb copied
* with \a prop_dictionary_copy() so it must be released when not required * with \a prop_dictionary_copy() so it must be released when not required
* anymore with prop_object_release(). NULL otherwise. * anymore with prop_object_release(). NULL otherwise.
*/ */
prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver); prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp,
const char *pkgver);
/** /**
* Removes a package dictionary from master package database (pkgdb) plist, * Removes a package dictionary from master package database (pkgdb) plist,
* matching pkgname or pkgver object in \a pkg. * matching pkgname or pkgver object in \a pkg.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkg Package name or pattern to match in a package dictionary. * @param[in] pkg Package name or pattern to match in a package dictionary.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
* package pattern, i.e `foo>=0' or `foo<1'. * package pattern, i.e `foo>=0' or `foo<1'.
@ -736,12 +748,16 @@ prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver);
* *
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush); bool xbps_pkgdb_remove_pkgd(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool flush);
/** /**
* Replaces a package dictionary with \a dict in the master package database * Replaces a package dictionary with \a dict in the master package database
* (pkgdb) plist, matching pkgname or pkgver object. * (pkgdb) plist, matching pkgname or pkgver object.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgd Proplib dictionary to be added into pkgdb. * @param[in] pkgd Proplib dictionary to be added into pkgdb.
* @param[in] pkg Package name or pattern to match in a package dictionary. * @param[in] pkg Package name or pattern to match in a package dictionary.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
@ -751,7 +767,8 @@ bool xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush);
* *
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd, bool xbps_pkgdb_replace_pkgd(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkg, const char *pkg,
bool bypattern, bool bypattern,
bool flush); bool flush);
@ -760,12 +777,13 @@ bool xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
* Updates the master package database (pkgdb) plist with new contents from * Updates the master package database (pkgdb) plist with new contents from
* disk to the cached copy in memory. * disk to the cached copy in memory.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] flush If true the pkgdb plist contents in memory will * @param[in] flush If true the pkgdb plist contents in memory will
* be flushed atomically to storage. * be flushed atomically to storage.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_pkgdb_update(bool flush); int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush);
/*@}*/ /*@}*/
@ -810,8 +828,9 @@ bool xbps_add_obj_to_array(prop_array_t array, prop_object_t obj);
* @return 0 on success, otherwise the value returned by the function * @return 0 on success, otherwise the value returned by the function
* callback. * callback.
*/ */
int xbps_callback_array_iter(prop_array_t array, int xbps_callback_array_iter(struct xbps_handle *xhp,
int (*fn)(prop_object_t, void *, bool *), prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
@ -827,8 +846,9 @@ int xbps_callback_array_iter(prop_array_t array,
* @return 0 on success, otherwise the value returned by the function * @return 0 on success, otherwise the value returned by the function
* callback. * callback.
*/ */
int xbps_callback_array_iter_reverse(prop_array_t array, int xbps_callback_array_iter_reverse(struct xbps_handle *xhp,
int (*fn)(prop_object_t, void *, bool *), prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
@ -846,9 +866,10 @@ int xbps_callback_array_iter_reverse(prop_array_t array,
* @return 0 on success (all objects were processed), otherwise * @return 0 on success (all objects were processed), otherwise
* the value returned by the function callback. * the value returned by the function callback.
*/ */
int xbps_callback_array_iter_in_dict(prop_dictionary_t dict, int xbps_callback_array_iter_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
@ -866,10 +887,12 @@ int xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
* @return 0 on success (all objects were processed), otherwise * @return 0 on success (all objects were processed), otherwise
* the value returned by the function callback. * the value returned by the function callback.
*/ */
int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, int xbps_callback_array_iter_reverse_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
* Finds the proplib's dictionary associated with a package, by looking * Finds the proplib's dictionary associated with a package, by looking
* it via its name in a proplib dictionary. * it via its name in a proplib dictionary.
@ -957,6 +980,7 @@ prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d,
* Finds a package's dictionary searching in the registered packages * Finds a package's dictionary searching in the registered packages
* database by using a package name or a package pattern. * database by using a package name or a package pattern.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] str Package name or package pattern. * @param[in] str Package name or package pattern.
* @param[in] bypattern Set it to true to find the package dictionary * @param[in] bypattern Set it to true to find the package dictionary
* by using a package pattern. If false, \a str is assumed to be a package name. * by using a package pattern. If false, \a str is assumed to be a package name.
@ -966,7 +990,8 @@ prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d,
* @note When returned dictionary is no longer needed, it must be released * @note When returned dictionary is no longer needed, it must be released
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_find_pkg_dict_installed(const char *str, prop_dictionary_t xbps_find_pkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern); bool bypattern);
@ -974,6 +999,7 @@ prop_dictionary_t xbps_find_pkg_dict_installed(const char *str,
* Finds a virtual package's dictionary searching in the registered packages * Finds a virtual package's dictionary searching in the registered packages
* database by using a package name or a package pattern. * database by using a package name or a package pattern.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] str Virtual package name or package pattern to match. * @param[in] str Virtual package name or package pattern to match.
* @param[in] bypattern Set it to true to find the package dictionary * @param[in] bypattern Set it to true to find the package dictionary
* by using a package pattern. If false, \a str is assumed to be a package name. * by using a package pattern. If false, \a str is assumed to be a package name.
@ -983,7 +1009,8 @@ prop_dictionary_t xbps_find_pkg_dict_installed(const char *str,
* @note When returned dictionary is no longer needed, it must be released * @note When returned dictionary is no longer needed, it must be released
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_find_virtualpkg_dict_installed(const char *str, prop_dictionary_t xbps_find_virtualpkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern); bool bypattern);
/** /**
@ -1141,13 +1168,15 @@ prop_object_iterator_t xbps_array_iter_from_dict(prop_dictionary_t dict,
* Returns a proplib object dictionary associated with the installed package * Returns a proplib object dictionary associated with the installed package
* \a pkgname, by internalizing its plist file defined in \a plist. * \a pkgname, by internalizing its plist file defined in \a plist.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgname Package name of installed package. * @param[in] pkgname Package name of installed package.
* @param[in] plist Package metadata property list file. * @param[in] plist Package metadata property list file.
* *
* @return The proplib object dictionary on success, NULL otherwise and * @return The proplib object dictionary on success, NULL otherwise and
* errno is set appropiately. * errno is set appropiately.
*/ */
prop_dictionary_t xbps_dictionary_from_metadata_plist(const char *pkgname, prop_dictionary_t xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
const char *pkgname,
const char *plist); const char *plist);
/** /**
@ -1256,6 +1285,7 @@ int xbps_array_replace_dict_by_pattern(prop_array_t array,
/** /**
* Register a package into the installed packages database. * Register a package into the installed packages database.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkg_dict A dictionary with the following objects: * @param[in] pkg_dict A dictionary with the following objects:
* \a pkgname, \a version, \a pkgver, \a short_desc (string), * \a pkgname, \a version, \a pkgver, \a short_desc (string),
* \a automatic-install (bool) and optionally \a provides (array of strings). * \a automatic-install (bool) and optionally \a provides (array of strings).
@ -1264,11 +1294,14 @@ int xbps_array_replace_dict_by_pattern(prop_array_t array,
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_register_pkg(prop_dictionary_t pkg_dict, bool flush); int xbps_register_pkg(struct xbps_handle *xhp,
prop_dictionary_t pkg_dict,
bool flush);
/** /**
* Unregister a package from the package database. * Unregister a package from the package database.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* @param[in] version Package version. * @param[in] version Package version.
* @param[in] flush Set to true to make sure that pkgdb plist * @param[in] flush Set to true to make sure that pkgdb plist
@ -1276,7 +1309,10 @@ int xbps_register_pkg(prop_dictionary_t pkg_dict, bool flush);
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_unregister_pkg(const char *pkgname, const char *version, bool flush); int xbps_unregister_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool flush);
/*@}*/ /*@}*/
@ -1286,6 +1322,7 @@ int xbps_unregister_pkg(const char *pkgname, const char *version, bool flush);
/** /**
* Remove an installed package. * Remove an installed package.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgname Package name to match. * @param[in] pkgname Package name to match.
* @param[in] version Package version associated. * @param[in] version Package version associated.
* @param[in] update If true, some steps will be skipped. See in the * @param[in] update If true, some steps will be skipped. See in the
@ -1295,13 +1332,17 @@ int xbps_unregister_pkg(const char *pkgname, const char *version, bool flush);
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_remove_pkg(const char *pkgname, const char *version, bool update, int xbps_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool update,
bool soft_replace); bool soft_replace);
/** /**
* Remove files defined in a proplib array as specified by \a key * Remove files defined in a proplib array as specified by \a key
* of an installed package. * of an installed package.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] dict Proplib dictionary internalized from package's * @param[in] dict Proplib dictionary internalized from package's
* <b>XBPS_PKGFILES</b> definition in package's metadata directory. * <b>XBPS_PKGFILES</b> definition in package's metadata directory.
* The image in Detailed description shows off its structure. * The image in Detailed description shows off its structure.
@ -1312,7 +1353,8 @@ int xbps_remove_pkg(const char *pkgname, const char *version, bool update,
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_remove_pkg_files(prop_dictionary_t dict, int xbps_remove_pkg_files(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
const char *pkgver); const char *pkgver);
@ -1327,9 +1369,10 @@ int xbps_remove_pkg_files(prop_dictionary_t dict,
* package version in repository pool will be queued, otherwise the first * package version in repository pool will be queued, otherwise the first
* repository matching the package pattern wins. * repository matching the package pattern wins.
* *
* @param pkg Package name, package/version or package pattern to match, i.e * @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkg Package name, package/version or package pattern to match, i.e
* `foo', `foo-1.0' or `foo>=1.2'. * `foo', `foo-1.0' or `foo>=1.2'.
* @param reinstall If true, package will be queued (if \a str matches) * @param[in] reinstall If true, package will be queued (if \a str matches)
* even if package is already installed. * even if package is already installed.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
@ -1338,7 +1381,9 @@ int xbps_remove_pkg_files(prop_dictionary_t dict,
* @retval ENOTSUP No repositories are available. * @retval ENOTSUP No repositories are available.
* @retval EINVAL Any other error ocurred in the process. * @retval EINVAL Any other error ocurred in the process.
*/ */
int xbps_transaction_install_pkg(const char *pkg, bool reinstall); int xbps_transaction_install_pkg(struct xbps_handle *xhp,
const char *pkg,
bool reinstall);
/** /**
* Marks a package as "going to be updated" in the transaction dictionary. * Marks a package as "going to be updated" in the transaction dictionary.
@ -1346,25 +1391,28 @@ int xbps_transaction_install_pkg(const char *pkg, bool reinstall);
* available will be enqueued if it's greater than current installed * available will be enqueued if it's greater than current installed
* version. * version.
* *
* @param pkgname The package name to update. * @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkgname The package name to update.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_transaction_update_pkg(const char *pkgname); int xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkgname);
/** /**
* Finds newer versions for all installed packages by looking at the * Finds newer versions for all installed packages by looking at the
* repository pool. If a newer version exists, package will be enqueued * repository pool. If a newer version exists, package will be enqueued
* into the transaction dictionary. * into the transaction dictionary.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_transaction_update_packages(void); int xbps_transaction_update_packages(struct xbps_handle *xhp);
/** /**
* Removes a package currently installed. The package dictionary will * Removes a package currently installed. The package dictionary will
* be added into the transaction dictionary. * be added into the transaction dictionary.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkgname Package name to be removed. * @param[in] pkgname Package name to be removed.
* @param[in] recursive If true, all packages that are currently depending * @param[in] recursive If true, all packages that are currently depending
* on the package to be removed, and if they are orphans, will be added. * on the package to be removed, and if they are orphans, will be added.
@ -1375,25 +1423,30 @@ int xbps_transaction_update_packages(void);
* @retval EINVAL * @retval EINVAL
* @retval ENXIO A problem ocurred in the process. * @retval ENXIO A problem ocurred in the process.
*/ */
int xbps_transaction_remove_pkg(const char *pkgname, int xbps_transaction_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool recursive); bool recursive);
/** /**
* Finds all package orphans currently installed and adds them into * Finds all package orphans currently installed and adds them into
* the transaction dictionary. * the transaction dictionary.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
*
* @retval 0 success. * @retval 0 success.
* @retval ENOENT No package orphans were found. * @retval ENOENT No package orphans were found.
* @retval ENXIO * @retval ENXIO
* @retval EINVAL A problem ocurred in the process. * @retval EINVAL A problem ocurred in the process.
*/ */
int xbps_transaction_autoremove_pkgs(void); int xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp);
/** /**
* Returns the transaction dictionary, as shown above in the image. * Returns the transaction dictionary, as shown above in the image.
* Before returning the package list is sorted in the correct order * Before returning the package list is sorted in the correct order
* and total installed/download size for the transaction is computed. * and total installed/download size for the transaction is computed.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
*
* @retval 0 success. * @retval 0 success.
* @retval ENXIO if transaction dictionary and missing deps array were not created, * @retval ENXIO if transaction dictionary and missing deps array were not created,
* due to xbps_transaction_install_pkg() or xbps_transaction_update_pkg() not * due to xbps_transaction_install_pkg() or xbps_transaction_update_pkg() not
@ -1403,16 +1456,17 @@ int xbps_transaction_autoremove_pkgs(void);
* @retval EINVAL There was an error sorting packages or computing the transaction * @retval EINVAL There was an error sorting packages or computing the transaction
* sizes. * sizes.
*/ */
int xbps_transaction_prepare(void); int xbps_transaction_prepare(struct xbps_handle *xhp);
/** /**
* Commit a transaction. The transaction dictionary in xhp->transd contains all * Commit a transaction. The transaction dictionary in xhp->transd contains all
* steps to be executed in the transaction, as prepared by * steps to be executed in the transaction, as prepared by
* xbps_transaction_prepare(). * xbps_transaction_prepare().
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_transaction_commit(void); int xbps_transaction_commit(struct xbps_handle *xhp);
/*@}*/ /*@}*/
@ -1466,12 +1520,13 @@ struct xbps_rpool_index {
* as specified in the configuration file or if \a uri argument is * as specified in the configuration file or if \a uri argument is
* set, just sync the index file for that repository. * set, just sync the index file for that repository.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] uri Repository URI to match for sync (optional). * @param[in] uri Repository URI to match for sync (optional).
* *
* @return 0 on success, ENOTSUP if no repositories were found in * @return 0 on success, ENOTSUP if no repositories were found in
* the configuration file. * the configuration file.
*/ */
int xbps_rpool_sync(const char *uri); int xbps_rpool_sync(struct xbps_handle *xhp, const char *uri);
/** /**
* Iterates over the repository pool and executes the \a fn function * Iterates over the repository pool and executes the \a fn function
@ -1480,6 +1535,7 @@ int xbps_rpool_sync(const char *uri);
* set to true, otherwise it will only be stopped if it returns a * set to true, otherwise it will only be stopped if it returns a
* non-zero value. * non-zero value.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] fn Function callback to execute for every repository registered in * @param[in] fn Function callback to execute for every repository registered in
* the pool. * the pool.
* @param[in] arg Opaque data passed in to the \a fn function callback for * @param[in] arg Opaque data passed in to the \a fn function callback for
@ -1487,13 +1543,16 @@ int xbps_rpool_sync(const char *uri);
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *arg); int xbps_rpool_foreach(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, struct xbps_rpool_index *, void *, bool *),
void *arg);
/** /**
* Finds a package dictionary in the repository pool by specifying a * Finds a package dictionary in the repository pool by specifying a
* package pattern or a package name. This function does not take into * package pattern or a package name. This function does not take into
* account virtual packages, just matches real packages. * account virtual packages, just matches real packages.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkg Package pattern or name. * @param[in] pkg Package pattern or name.
* @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0), * @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0),
* false if it is a pkgname. * false if it is a pkgname.
@ -1504,24 +1563,30 @@ int xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), voi
* @note When returned dictionary is no longer needed, you must release it * @note When returned dictionary is no longer needed, you must release it
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_rpool_find_pkg(const char *pkg, bool bypattern, bool best); prop_dictionary_t xbps_rpool_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best);
/** /**
* Finds a package dictionary in repository pool by matching its \a pkgver * Finds a package dictionary in repository pool by matching its \a pkgver
* object. * object.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkgver Package name/version to match, i.e `foo-1.0'. * @param[in] pkgver Package name/version to match, i.e `foo-1.0'.
* *
* @return The package dictionary if found, NULL otherwise. * @return The package dictionary if found, NULL otherwise.
* @note When returned dictionary is no longer needed, you must release it * @note When returned dictionary is no longer needed, you must release it
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_rpool_find_pkg_exact(const char *pkgver); prop_dictionary_t xbps_rpool_find_pkg_exact(struct xbps_handle *xhp,
const char *pkgver);
/** /**
* Finds a package dictionary in repository pool by specifying a * Finds a package dictionary in repository pool by specifying a
* virtual package pattern or a package name. * virtual package pattern or a package name.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkg Virtual package pattern or name to match. * @param[in] pkg Virtual package pattern or name to match.
* @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0), * @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0),
* false if it is a pkgname. * false if it is a pkgname.
@ -1530,13 +1595,16 @@ prop_dictionary_t xbps_rpool_find_pkg_exact(const char *pkgver);
* @note When returned dictionary is no longer needed, you must release it * @note When returned dictionary is no longer needed, you must release it
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern); prop_dictionary_t xbps_rpool_find_virtualpkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern);
/** /**
* Finds a package dictionary in repository pool by specifying a * Finds a package dictionary in repository pool by specifying a
* package pattern or a package name. Only virtual packages set in * package pattern or a package name. Only virtual packages set in
* configuration file will be matched. * configuration file will be matched.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pkg Virtual package pattern or name to match. * @param[in] pkg Virtual package pattern or name to match.
* @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0), * @param[in] bypattern Set it to true if \a pkg is a pkgpattern (foo>=0),
* false if it is a pkgname. * false if it is a pkgname.
@ -1545,7 +1613,9 @@ prop_dictionary_t xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern);
* @note When returned dictionary is no longer needed, you must release it * @note When returned dictionary is no longer needed, you must release it
* with prop_object_release(3). * with prop_object_release(3).
*/ */
prop_dictionary_t xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypattern); prop_dictionary_t xbps_rpool_find_virtualpkg_conf(struct xbps_handle *xhp,
const char *pkg,
bool bypattern);
/** /**
* Iterate over the the repository pool and search for a metadata plist * Iterate over the the repository pool and search for a metadata plist
@ -1555,6 +1625,7 @@ prop_dictionary_t xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypatter
* When \a pattern is a pkgname, the newest package available in repositories * When \a pattern is a pkgname, the newest package available in repositories
* will be used. Otherwise the first repository matching \a pattern. * will be used. Otherwise the first repository matching \a pattern.
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] pattern Package name or package pattern to match, i.e `foo>=1.0'. * @param[in] pattern Package name or package pattern to match, i.e `foo>=1.0'.
* @param[in] plistf Plist file name to match, i.e XBPS_PKGPROPS or XBPS_PKGFILES. * @param[in] plistf Plist file name to match, i.e XBPS_PKGPROPS or XBPS_PKGFILES.
* *
@ -1565,7 +1636,8 @@ prop_dictionary_t xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypatter
* binary package file has been found but the plist file could not * binary package file has been found but the plist file could not
* be found. * be found.
*/ */
prop_dictionary_t xbps_rpool_dictionary_metadata_plist(const char *pattern, prop_dictionary_t xbps_rpool_dictionary_metadata_plist(struct xbps_handle *xhp,
const char *pattern,
const char *plistf); const char *plistf);
/*@}*/ /*@}*/
@ -1577,6 +1649,7 @@ prop_dictionary_t xbps_rpool_dictionary_metadata_plist(const char *pattern,
* Syncs the package index file for a remote repository as specified * Syncs the package index file for a remote repository as specified
* by the \a uri argument (if necessary). * by the \a uri argument (if necessary).
* *
* @param[in] xhp Pointer to the xbps_handle struct.
* @param[in] uri URI to a remote repository. * @param[in] uri URI to a remote repository.
* @param[in] plistf Plist file to sync. * @param[in] plistf Plist file to sync.
* *
@ -1584,7 +1657,9 @@ prop_dictionary_t xbps_rpool_dictionary_metadata_plist(const char *pattern,
* not necessary (local/remote size/mtime matched) or 1 if * not necessary (local/remote size/mtime matched) or 1 if
* downloaded successfully. * downloaded successfully.
*/ */
int xbps_repository_sync_pkg_index(const char *uri, const char *plistf); int xbps_repository_sync_pkg_index(struct xbps_handle *xhp,
const char *uri,
const char *plistf);
/*@}*/ /*@}*/
@ -1622,12 +1697,15 @@ typedef enum pkg_state {
* Gets package state from package \a pkgname, and sets its state * Gets package state from package \a pkgname, and sets its state
* into \a state. * into \a state.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* @param[out] state Package state returned. * @param[out] state Package state returned.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state); int xbps_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
pkg_state_t *state);
/** /**
* Gets package state from a package dictionary \a dict, and sets its * Gets package state from a package dictionary \a dict, and sets its
@ -1643,13 +1721,15 @@ int xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state);
/** /**
* Sets package state \a state in package \a pkgname. * Sets package state \a state in package \a pkgname.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* @param[in] version Package version. * @param[in] version Package version.
* @param[in] state Package state to be set. * @param[in] state Package state to be set.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_set_pkg_state_installed(const char *pkgname, int xbps_set_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
const char *version, const char *version,
pkg_state_t state); pkg_state_t state);
@ -1732,13 +1812,15 @@ int xbps_file_hash_check(const char *file, const char *sha256);
* Checks if \a file matches the sha256 hash specified in the array * Checks if \a file matches the sha256 hash specified in the array
* with key \a key in the proplib dictionary \a d. * with key \a key in the proplib dictionary \a d.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] d Proplib dictionary to look in. * @param[in] d Proplib dictionary to look in.
* @param[in] key Proplib array key to match for file. * @param[in] key Proplib array key to match for file.
* @param[in] file Pathname to a file. * @param[in] file Pathname to a file.
* *
* @return 0 if hash is matched, -1 on error and 1 if no match. * @return 0 if hash is matched, -1 on error and 1 if no match.
*/ */
int xbps_file_hash_check_dictionary(prop_dictionary_t d, int xbps_file_hash_check_dictionary(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *file); const char *file);
@ -1746,22 +1828,26 @@ int xbps_file_hash_check_dictionary(prop_dictionary_t d,
* Checks if a package is currently installed by matching a package * Checks if a package is currently installed by matching a package
* pattern string. * pattern string.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] pkg Package pattern used to find the package. * @param[in] pkg Package pattern used to find the package.
* *
* @return -1 on error (errno set appropiately), 0 if package pattern * @return -1 on error (errno set appropiately), 0 if package pattern
* didn't match installed package, 1 if \a pkg pattern fully * didn't match installed package, 1 if \a pkg pattern fully
* matched installed package. * matched installed package.
*/ */
int xbps_check_is_installed_pkg_by_pattern(const char *pkg); int xbps_check_is_installed_pkg_by_pattern(struct xbps_handle *xhp,
const char *pkg);
/** /**
* Checks if package \a pkgname is currently installed. * Checks if package \a pkgname is currently installed.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* *
* @return True if \a pkgname is installed, false otherwise. * @return True if \a pkgname is installed, false otherwise.
*/ */
bool xbps_check_is_installed_pkg_by_name(const char *pkgname); bool xbps_check_is_installed_pkg_by_name(struct xbps_handle *xhp,
const char *pkgname);
/** /**
* Checks if the URI specified by \a uri is remote or local. * Checks if the URI specified by \a uri is remote or local.
@ -1777,6 +1863,7 @@ bool xbps_check_is_repository_uri_remote(const char *uri);
* package dictionary from a repository in \a pkgd, by looking at the * package dictionary from a repository in \a pkgd, by looking at the
* repository location object "repository" in its dictionary. * repository location object "repository" in its dictionary.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] pkgd Package dictionary stored in a transaction dictionary. * @param[in] pkgd Package dictionary stored in a transaction dictionary.
* @param[in] repoloc Repository URL location string. * @param[in] repoloc Repository URL location string.
* *
@ -1784,31 +1871,35 @@ bool xbps_check_is_repository_uri_remote(const char *uri);
* errno is set appropiately. The pointer should be free(3)d when it's * errno is set appropiately. The pointer should be free(3)d when it's
* no longer needed. * no longer needed.
*/ */
char *xbps_path_from_repository_uri(prop_dictionary_t pkgd, const char *repoloc); char *xbps_path_from_repository_uri(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *repoloc);
/** /**
* Gets the full path to a repository package index plist file, as * Gets the full path to a repository package index plist file, as
* specified by \a uri. * specified by \a uri.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] uri Repository URI. * @param[in] uri Repository URI.
* *
* @return A pointer to a malloc(3)d string, NULL otherwise and * @return A pointer to a malloc(3)d string, NULL otherwise and
* errno is set appropiately. The pointer should be free(3)d when it's * errno is set appropiately. The pointer should be free(3)d when it's
* no longer needed. * no longer needed.
*/ */
char *xbps_pkg_index_plist(const char *uri); char *xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri);
/** /**
* Returns the full path to a repository package index files plist file, * Returns the full path to a repository package index files plist file,
* as specified by \a uri. * as specified by \a uri.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] uri Repository URI. * @param[in] uri Repository URI.
* *
* @return A pointer to a malloc(3)ed string, NULL otherwise and * @return A pointer to a malloc(3)ed string, NULL otherwise and
* errno is set appropiately. The pointer should be free(3)d when it's * errno is set appropiately. The pointer should be free(3)d when it's
* no longer needded. * no longer needded.
*/ */
char *xbps_pkg_index_files_plist(const char *uri); char *xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri);
/** /**
* Gets the name of a package string. Package strings are composed * Gets the name of a package string. Package strings are composed

View File

@ -90,7 +90,8 @@ void HIDDEN xbps_fetch_unset_cache_connection(void);
* From lib/package_config_files.c * From lib/package_config_files.c
*/ */
int HIDDEN xbps_entry_is_a_conf_file(prop_dictionary_t, const char *); int HIDDEN xbps_entry_is_a_conf_file(prop_dictionary_t, const char *);
int HIDDEN xbps_entry_install_conf_file(prop_dictionary_t, int HIDDEN xbps_entry_install_conf_file(struct xbps_handle *,
prop_dictionary_t,
struct archive_entry *, struct archive_entry *,
const char *, const char *,
const char *, const char *,
@ -107,7 +108,8 @@ prop_dictionary_t HIDDEN
* @private * @private
* From lib/package_remove_obsoletes.c * From lib/package_remove_obsoletes.c
*/ */
int HIDDEN xbps_remove_obsoletes(const char *, int HIDDEN xbps_remove_obsoletes(struct xbps_handle *xhp,
const char *,
const char *, const char *,
const char *, const char *,
prop_dictionary_t, prop_dictionary_t,
@ -125,16 +127,20 @@ int HIDDEN xbps_repository_find_pkg_deps(struct xbps_handle *,
* From lib/package_requiredby.c * From lib/package_requiredby.c
*/ */
int HIDDEN xbps_requiredby_pkg_add(struct xbps_handle *, prop_dictionary_t); int HIDDEN xbps_requiredby_pkg_add(struct xbps_handle *, prop_dictionary_t);
int HIDDEN xbps_requiredby_pkg_remove(const char *); int HIDDEN xbps_requiredby_pkg_remove(struct xbps_handle *, const char *);
/** /**
* @private * @private
* From lib/plist_find.c * From lib/plist_find.c
*/ */
prop_dictionary_t HIDDEN prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_name(prop_array_t, const char *); xbps_find_virtualpkg_conf_in_array_by_name(struct xbps_handle *,
prop_array_t,
const char *);
prop_dictionary_t HIDDEN prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t, const char *); xbps_find_virtualpkg_conf_in_array_by_pattern(struct xbps_handle *,
prop_array_t,
const char *);
/** /**
* @private * @private
@ -158,28 +164,28 @@ char HIDDEN *xbps_get_remote_repo_string(const char *);
* @private * @private
* From lib/external/fexec.c * From lib/external/fexec.c
*/ */
int HIDDEN xbps_file_exec(const char *, ...); int HIDDEN xbps_file_exec(struct xbps_handle *, const char *, ...);
/** /**
* @private * @private
* From lib/transaction_package_replace.c * From lib/transaction_package_replace.c
*/ */
int HIDDEN xbps_transaction_package_replace(prop_dictionary_t); int HIDDEN xbps_transaction_package_replace(struct xbps_handle *);
/** /**
* @private * @private
* From lib/cb_util.c * From lib/cb_util.c
*/ */
void HIDDEN xbps_set_cb_fetch(off_t, off_t, off_t, const char *, void HIDDEN xbps_set_cb_fetch(struct xbps_handle *, off_t, off_t, off_t,
bool, bool, bool); const char *, bool, bool, bool);
void HIDDEN xbps_set_cb_state(xbps_state_t, int, const char *, void HIDDEN xbps_set_cb_state(struct xbps_handle *, xbps_state_t, int,
const char *, const char *, ...); const char *, const char *, const char *, ...);
/** /**
* @private * @private
* From lib/package_unpack.c * From lib/package_unpack.c
*/ */
int HIDDEN xbps_unpack_binary_pkg(prop_dictionary_t); int HIDDEN xbps_unpack_binary_pkg(struct xbps_handle *, prop_dictionary_t);
/** /**
* @private * @private

View File

@ -41,7 +41,8 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
void HIDDEN void HIDDEN
xbps_set_cb_fetch(off_t file_size, xbps_set_cb_fetch(struct xbps_handle *xhp,
off_t file_size,
off_t file_offset, off_t file_offset,
off_t file_dloaded, off_t file_dloaded,
const char *file_name, const char *file_name,
@ -49,7 +50,6 @@ xbps_set_cb_fetch(off_t file_size,
bool cb_update, bool cb_update,
bool cb_end) bool cb_end)
{ {
const struct xbps_handle *xhp = xbps_handle_get();
struct xbps_fetch_cb_data xfcd; struct xbps_fetch_cb_data xfcd;
if (xhp->fetch_cb == NULL) if (xhp->fetch_cb == NULL)
@ -62,11 +62,12 @@ xbps_set_cb_fetch(off_t file_size,
xfcd.cb_start = cb_start; xfcd.cb_start = cb_start;
xfcd.cb_update = cb_update; xfcd.cb_update = cb_update;
xfcd.cb_end = cb_end; xfcd.cb_end = cb_end;
(*xhp->fetch_cb)(&xfcd, xhp->fetch_cb_data); (*xhp->fetch_cb)(xhp, &xfcd, xhp->fetch_cb_data);
} }
void HIDDEN void HIDDEN
xbps_set_cb_state(xbps_state_t state, xbps_set_cb_state(struct xbps_handle *xhp,
xbps_state_t state,
int err, int err,
const char *pkgname, const char *pkgname,
const char *version, const char *version,
@ -74,7 +75,6 @@ xbps_set_cb_state(xbps_state_t state,
...) ...)
{ {
struct xbps_state_cb_data xscd; struct xbps_state_cb_data xscd;
const struct xbps_handle *xhp = xbps_handle_get();
char *buf = NULL; char *buf = NULL;
va_list va; va_list va;
int retval; int retval;
@ -95,7 +95,7 @@ xbps_set_cb_state(xbps_state_t state,
else else
xscd.desc = buf; xscd.desc = buf;
} }
(*xhp->state_cb)(&xscd, xhp->fetch_cb_data); (*xhp->state_cb)(xhp, &xscd, xhp->fetch_cb_data);
if (buf != NULL) if (buf != NULL)
free(buf); free(buf);
} }

View File

@ -88,12 +88,12 @@ xbps_fetch_error_string(void)
} }
int int
xbps_fetch_file(const char *uri, xbps_fetch_file(struct xbps_handle *xhp,
const char *uri,
const char *outputdir, const char *outputdir,
bool refetch, bool refetch,
const char *flags) const char *flags)
{ {
struct xbps_handle *xhp;
struct stat st; struct stat st;
struct url *url = NULL; struct url *url = NULL;
struct url_stat url_st; struct url_stat url_st;
@ -110,7 +110,6 @@ xbps_fetch_file(const char *uri,
fetchLastErrCode = 0; fetchLastErrCode = 0;
xhp = xbps_handle_get();
fetchTimeout = xhp->fetch_timeout; fetchTimeout = xhp->fetch_timeout;
/* /*
* Get the filename specified in URI argument. * Get the filename specified in URI argument.
@ -196,20 +195,20 @@ xbps_fetch_file(const char *uri,
} }
/* debug stuff */ /* debug stuff */
xbps_dbg_printf("st.st_size: %zd\n", (ssize_t)st.st_size); xbps_dbg_printf(xhp, "st.st_size: %zd\n", (ssize_t)st.st_size);
xbps_dbg_printf("st.st_atime: %s\n", print_time(&st.st_atime)); xbps_dbg_printf(xhp, "st.st_atime: %s\n", print_time(&st.st_atime));
xbps_dbg_printf("st.st_mtime: %s\n", print_time(&st.st_mtime)); xbps_dbg_printf(xhp, "st.st_mtime: %s\n", print_time(&st.st_mtime));
xbps_dbg_printf("url->scheme: %s\n", url->scheme); xbps_dbg_printf(xhp, "url->scheme: %s\n", url->scheme);
xbps_dbg_printf("url->host: %s\n", url->host); xbps_dbg_printf(xhp, "url->host: %s\n", url->host);
xbps_dbg_printf("url->port: %d\n", url->port); xbps_dbg_printf(xhp, "url->port: %d\n", url->port);
xbps_dbg_printf("url->doc: %s\n", url->doc); xbps_dbg_printf(xhp, "url->doc: %s\n", url->doc);
xbps_dbg_printf("url->offset: %zd\n", (ssize_t)url->offset); xbps_dbg_printf(xhp, "url->offset: %zd\n", (ssize_t)url->offset);
xbps_dbg_printf("url->length: %zu\n", url->length); xbps_dbg_printf(xhp, "url->length: %zu\n", url->length);
xbps_dbg_printf("url->last_modified: %s\n", xbps_dbg_printf(xhp, "url->last_modified: %s\n",
print_time(&url->last_modified)); print_time(&url->last_modified));
xbps_dbg_printf("url_stat.size: %zd\n", (ssize_t)url_st.size); xbps_dbg_printf(xhp, "url_stat.size: %zd\n", (ssize_t)url_st.size);
xbps_dbg_printf("url_stat.atime: %s\n", print_time(&url_st.atime)); xbps_dbg_printf(xhp, "url_stat.atime: %s\n", print_time(&url_st.atime));
xbps_dbg_printf("url_stat.mtime: %s\n", print_time(&url_st.mtime)); xbps_dbg_printf(xhp, "url_stat.mtime: %s\n", print_time(&url_st.mtime));
if (fio == NULL && fetchLastErrCode != FETCH_OK) { if (fio == NULL && fetchLastErrCode != FETCH_OK) {
if (!refetch && restart && fetchLastErrCode == FETCH_UNAVAIL) { if (!refetch && restart && fetchLastErrCode == FETCH_UNAVAIL) {
@ -226,7 +225,7 @@ xbps_fetch_file(const char *uri,
goto out; goto out;
} }
if (url_st.size == -1) { if (url_st.size == -1) {
xbps_dbg_printf("Remote file size is unknown, resume " xbps_dbg_printf(xhp, "Remote file size is unknown, resume "
"not possible...\n"); "not possible...\n");
restart = false; restart = false;
} else if (st.st_size > url_st.size) { } else if (st.st_size > url_st.size) {
@ -234,7 +233,7 @@ xbps_fetch_file(const char *uri,
* Remove local file if bigger than remote, and refetch the * Remove local file if bigger than remote, and refetch the
* whole shit again. * whole shit again.
*/ */
xbps_dbg_printf("Local file %s is greater than remote, " xbps_dbg_printf(xhp, "Local file %s is greater than remote, "
"removing local file and refetching...\n", filename); "removing local file and refetching...\n", filename);
(void)remove(destfile); (void)remove(destfile);
} else if (restart && url_st.mtime && url_st.size && } else if (restart && url_st.mtime && url_st.size &&
@ -259,7 +258,7 @@ xbps_fetch_file(const char *uri,
* and let the user know that the transfer is going to start * and let the user know that the transfer is going to start
* immediately. * immediately.
*/ */
xbps_set_cb_fetch(url_st.size, url->offset, url->offset, xbps_set_cb_fetch(xhp, url_st.size, url->offset, url->offset,
filename, true, false, false); filename, true, false, false);
/* /*
* Start fetching requested file. * Start fetching requested file.
@ -267,7 +266,7 @@ xbps_fetch_file(const char *uri,
while ((bytes_read = fetchIO_read(fio, buf, sizeof(buf))) > 0) { while ((bytes_read = fetchIO_read(fio, buf, sizeof(buf))) > 0) {
bytes_written = write(fd, buf, (size_t)bytes_read); bytes_written = write(fd, buf, (size_t)bytes_read);
if (bytes_written != bytes_read) { if (bytes_written != bytes_read) {
xbps_dbg_printf("Couldn't write to %s!\n", destfile); xbps_dbg_printf(xhp, "Couldn't write to %s!\n", destfile);
rv = -1; rv = -1;
goto out; goto out;
} }
@ -276,11 +275,12 @@ xbps_fetch_file(const char *uri,
* Let the fetch progress callback know that * Let the fetch progress callback know that
* we are sucking more bytes from it. * we are sucking more bytes from it.
*/ */
xbps_set_cb_fetch(url_st.size, url->offset, url->offset + bytes_dload, xbps_set_cb_fetch(xhp, url_st.size, url->offset,
url->offset + bytes_dload,
filename, false, true, false); filename, false, true, false);
} }
if (bytes_read == -1) { if (bytes_read == -1) {
xbps_dbg_printf("IO error while fetching %s: %s\n", filename, xbps_dbg_printf(xhp, "IO error while fetching %s: %s\n", filename,
fetchLastErrString); fetchLastErrString);
errno = EIO; errno = EIO;
rv = -1; rv = -1;
@ -294,7 +294,7 @@ xbps_fetch_file(const char *uri,
* Let the fetch progress callback know that the file * Let the fetch progress callback know that the file
* has been fetched. * has been fetched.
*/ */
xbps_set_cb_fetch(url_st.size, url->offset, bytes_dload, xbps_set_cb_fetch(xhp, url_st.size, url->offset, bytes_dload,
filename, false, false, true); filename, false, false, true);
/* /*
* Update mtime in local file to match remote file if transfer * Update mtime in local file to match remote file if transfer

19
lib/external/dewey.c vendored
View File

@ -137,19 +137,12 @@ mkcomponent(arr_t *ap, const char *num)
if (ap->c == ap->size) { if (ap->c == ap->size) {
if (ap->size == 0) { if (ap->size == 0) {
ap->size = 62; ap->size = 62;
if ((ap->v = malloc(ap->size * sizeof(int))) == NULL) { ap->v = malloc(ap->size * sizeof(int));
xbps_dbg_printf("%s: malloc ENOMEM\n", assert(ap->v != NULL);
__func__);
exit(EXIT_FAILURE);
}
} else { } else {
ap->size *= 2; ap->size *= 2;
ap->v = realloc(ap->v, ap->size * sizeof(int)); ap->v = realloc(ap->v, ap->size * sizeof(int));
if (ap->v == NULL) { assert(ap->v != NULL);
xbps_dbg_printf("%s: realloc ENOMEM\n",
__func__);
exit(EXIT_FAILURE);
}
} }
} }
if (isdigit((unsigned char)*num)) { if (isdigit((unsigned char)*num)) {
@ -177,10 +170,8 @@ mkcomponent(arr_t *ap, const char *num)
cp = strchr(alphas, tolower((unsigned char)*num)); cp = strchr(alphas, tolower((unsigned char)*num));
if (ap->c == ap->size) { if (ap->c == ap->size) {
ap->size *= 2; ap->size *= 2;
if ((ap->v = realloc(ap->v, ap->size * sizeof(int))) == NULL) { ap->v = realloc(ap->v, ap->size * sizeof(int));
xbps_dbg_printf("%s: ENOMEM!\n", __func__); assert(ap->v != NULL);
exit(EXIT_FAILURE);
}
} }
ap->v[ap->c++] = (int)(cp - alphas) + 1; ap->v[ap->c++] = (int)(cp - alphas) + 1;
return 1; return 1;

12
lib/external/fexec.c vendored
View File

@ -38,9 +38,8 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
static int static int
pfcexec(const char *file, const char **argv) pfcexec(struct xbps_handle *xhp, const char *file, const char **argv)
{ {
struct xbps_handle *xhp;
pid_t child; pid_t child;
int status; int status;
@ -53,7 +52,6 @@ pfcexec(const char *file, const char **argv)
* *
* It's assumed that cwd is the target rootdir. * It's assumed that cwd is the target rootdir.
*/ */
xhp = xbps_handle_get();
if (strcmp(xhp->rootdir, "/")) { if (strcmp(xhp->rootdir, "/")) {
if (getuid() == 0 && access("bin/sh", X_OK) == 0) { if (getuid() == 0 && access("bin/sh", X_OK) == 0) {
if (chroot(xhp->rootdir) == -1) if (chroot(xhp->rootdir) == -1)
@ -81,7 +79,7 @@ pfcexec(const char *file, const char **argv)
} }
static int static int
vfcexec(const char *arg, va_list ap) vfcexec(struct xbps_handle *xhp, const char *arg, va_list ap)
{ {
const char **argv; const char **argv;
size_t argv_size, argc; size_t argv_size, argc;
@ -111,20 +109,20 @@ vfcexec(const char *arg, va_list ap)
} while (arg != NULL); } while (arg != NULL);
retval = pfcexec(argv[0], argv); retval = pfcexec(xhp, argv[0], argv);
free(argv); free(argv);
return retval; return retval;
} }
int HIDDEN int HIDDEN
xbps_file_exec(const char *arg, ...) xbps_file_exec(struct xbps_handle *xhp, const char *arg, ...)
{ {
va_list ap; va_list ap;
int result; int result;
va_start(ap, arg); va_start(ap, arg);
result = vfcexec(arg, ap); result = vfcexec(xhp, arg, ap);
va_end(ap); va_end(ap);
return result; return result;

View File

@ -39,9 +39,7 @@
* Use these functions to initialize some parameters before start * Use these functions to initialize some parameters before start
* using libxbps and finalize usage to release resources at the end. * using libxbps and finalize usage to release resources at the end.
*/ */
static bool debug;
static bool xbps_initialized; static bool xbps_initialized;
static struct xbps_handle *xhp;
static char * static char *
set_cachedir(struct xbps_handle *xh) set_cachedir(struct xbps_handle *xh)
@ -89,7 +87,7 @@ cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
} }
int int
xbps_init(struct xbps_handle *xh) xbps_init(struct xbps_handle *xhp)
{ {
cfg_opt_t vpkg_opts[] = { cfg_opt_t vpkg_opts[] = {
CFG_STR_LIST(__UNCONST("targets"), NULL, CFGF_NONE), CFG_STR_LIST(__UNCONST("targets"), NULL, CFGF_NONE),
@ -119,11 +117,7 @@ xbps_init(struct xbps_handle *xh)
int rv, cc, cch; int rv, cc, cch;
bool syslog_enabled = false; bool syslog_enabled = false;
assert(xh != NULL); assert(xhp != NULL);
xhp = xh;
if (xhp->flags & XBPS_FLAG_DEBUG)
debug = true;
if (xhp->conffile == NULL) if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_DEF; xhp->conffile = XBPS_CONF_DEF;
@ -150,7 +144,7 @@ xbps_init(struct xbps_handle *xh)
return ENOTSUP; return ENOTSUP;
} }
} }
xbps_dbg_printf("Configuration file: %s\n", xbps_dbg_printf(xhp, "Configuration file: %s\n",
xhp->conffile ? xhp->conffile : "not found"); xhp->conffile ? xhp->conffile : "not found");
/* /*
* Respect client setting in struct xbps_handle for {root,cache}dir; * Respect client setting in struct xbps_handle for {root,cache}dir;
@ -196,14 +190,14 @@ xbps_init(struct xbps_handle *xh)
xbps_fetch_set_cache_connection(cc, cch); xbps_fetch_set_cache_connection(cc, cch);
xbps_dbg_printf("Rootdir=%s\n", xhp->rootdir); xbps_dbg_printf(xhp, "Rootdir=%s\n", xhp->rootdir);
xbps_dbg_printf("Metadir=%s\n", xhp->metadir); xbps_dbg_printf(xhp, "Metadir=%s\n", xhp->metadir);
xbps_dbg_printf("Cachedir=%s\n", xhp->cachedir); xbps_dbg_printf(xhp, "Cachedir=%s\n", xhp->cachedir);
xbps_dbg_printf("FetchTimeout=%u\n", xhp->fetch_timeout); xbps_dbg_printf(xhp, "FetchTimeout=%u\n", xhp->fetch_timeout);
xbps_dbg_printf("FetchCacheconn=%u\n", cc); xbps_dbg_printf(xhp, "FetchCacheconn=%u\n", cc);
xbps_dbg_printf("FetchCacheconnHost=%u\n", cch); xbps_dbg_printf(xhp, "FetchCacheconnHost=%u\n", cch);
xbps_dbg_printf("Syslog=%u\n", syslog_enabled); xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled);
xbps_dbg_printf("TransactionFrequencyFlush=%u\n", xbps_dbg_printf(xhp, "TransactionFrequencyFlush=%u\n",
xhp->transaction_frequency_flush); xhp->transaction_frequency_flush);
xbps_initialized = true; xbps_initialized = true;
@ -212,7 +206,7 @@ xbps_init(struct xbps_handle *xh)
} }
void void
xbps_end(void) xbps_end(struct xbps_handle *xhp)
{ {
if (!xbps_initialized) if (!xbps_initialized)
return; return;
@ -232,12 +226,6 @@ xbps_end(void)
xbps_initialized = false; xbps_initialized = false;
} }
struct xbps_handle *
xbps_handle_get(void)
{
return xhp;
}
static void static void
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap) common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
{ {
@ -248,11 +236,11 @@ common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
} }
void void
xbps_dbg_printf_append(const char *fmt, ...) xbps_dbg_printf_append(struct xbps_handle *xhp, const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (!debug) if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
return; return;
va_start(ap, fmt); va_start(ap, fmt);
@ -261,11 +249,11 @@ xbps_dbg_printf_append(const char *fmt, ...)
} }
void void
xbps_dbg_printf(const char *fmt, ...) xbps_dbg_printf(struct xbps_handle *xhp, const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (!debug) if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
return; return;
va_start(ap, fmt); va_start(ap, fmt);

View File

@ -76,7 +76,8 @@ out:
* Returns 1 if entry should be installed, 0 if don't or -1 on error. * Returns 1 if entry should be installed, 0 if don't or -1 on error.
*/ */
int HIDDEN int HIDDEN
xbps_entry_install_conf_file(prop_dictionary_t filesd, xbps_entry_install_conf_file(struct xbps_handle *xhp,
prop_dictionary_t filesd,
struct archive_entry *entry, struct archive_entry *entry,
const char *entry_pname, const char *entry_pname,
const char *pkgname, const char *pkgname,
@ -103,12 +104,12 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
* Get original hash for the file from current * Get original hash for the file from current
* installed package. * installed package.
*/ */
xbps_dbg_printf("%s: processing conf_file %s\n", xbps_dbg_printf(xhp, "%s: processing conf_file %s\n",
pkgname, entry_pname); pkgname, entry_pname);
forigd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES); forigd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (forigd == NULL) { if (forigd == NULL) {
xbps_dbg_printf("%s: conf_file %s not currently installed\n", xbps_dbg_printf(xhp, "%s: conf_file %s not currently installed\n",
pkgname, entry_pname); pkgname, entry_pname);
rv = 1; rv = 1;
goto out; goto out;
@ -141,7 +142,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
* First case: original hash not found, install new file. * First case: original hash not found, install new file.
*/ */
if (sha256_orig == NULL) { if (sha256_orig == NULL) {
xbps_dbg_printf("%s: conf_file %s unknown orig sha256\n", xbps_dbg_printf(xhp, "%s: conf_file %s unknown orig sha256\n",
pkgname, entry_pname); pkgname, entry_pname);
rv = 1; rv = 1;
goto out; goto out;
@ -170,7 +171,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
/* /*
* File not installed, install new one. * File not installed, install new one.
*/ */
xbps_dbg_printf("%s: conf_file %s not " xbps_dbg_printf(xhp, "%s: conf_file %s not "
"installed\n", pkgname, entry_pname); "installed\n", pkgname, entry_pname);
rv = 1; rv = 1;
break; break;
@ -187,7 +188,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
if ((strcmp(sha256_orig, sha256_cur) == 0) && if ((strcmp(sha256_orig, sha256_cur) == 0) &&
(strcmp(sha256_orig, sha256_new) == 0) && (strcmp(sha256_orig, sha256_new) == 0) &&
(strcmp(sha256_cur, sha256_new) == 0)) { (strcmp(sha256_cur, sha256_new) == 0)) {
xbps_dbg_printf("%s: conf_file %s orig = X," xbps_dbg_printf(xhp, "%s: conf_file %s orig = X,"
"cur = X, new = X\n", pkgname, entry_pname); "cur = X, new = X\n", pkgname, entry_pname);
rv = 1; rv = 1;
break; break;
@ -199,7 +200,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_orig, sha256_cur) == 0) && } else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
(strcmp(sha256_orig, sha256_new)) && (strcmp(sha256_orig, sha256_new)) &&
(strcmp(sha256_cur, sha256_new))) { (strcmp(sha256_cur, sha256_new))) {
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version, 0, pkgname, version,
"Updating configuration file `%s' provided " "Updating configuration file `%s' provided "
"by version `%s'.", cffile, version); "by version `%s'.", cffile, version);
@ -212,7 +213,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_orig, sha256_new) == 0) && } else if ((strcmp(sha256_orig, sha256_new) == 0) &&
(strcmp(sha256_cur, sha256_new)) && (strcmp(sha256_cur, sha256_new)) &&
(strcmp(sha256_orig, sha256_cur))) { (strcmp(sha256_orig, sha256_cur))) {
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version, 0, pkgname, version,
"Keeping modified configuration file `%s'.", "Keeping modified configuration file `%s'.",
cffile); cffile);
@ -225,7 +226,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_cur, sha256_new) == 0) && } else if ((strcmp(sha256_cur, sha256_new) == 0) &&
(strcmp(sha256_orig, sha256_new)) && (strcmp(sha256_orig, sha256_new)) &&
(strcmp(sha256_orig, sha256_cur))) { (strcmp(sha256_orig, sha256_cur))) {
xbps_dbg_printf("%s: conf_file %s orig = X," xbps_dbg_printf(xhp, "%s: conf_file %s orig = X,"
"cur = Y, new = Y\n", pkgname, entry_pname); "cur = Y, new = Y\n", pkgname, entry_pname);
rv = 0; rv = 0;
break; break;
@ -242,7 +243,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
rv = -1; rv = -1;
break; break;
} }
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version, 0, pkgname, version,
"Installing new configuration file to " "Installing new configuration file to "
"`%s.new-%s'.", cffile, version); "`%s.new-%s'.", cffile, version);
@ -261,7 +262,7 @@ out:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
xbps_dbg_printf("%s: conf_file %s returned %d\n", xbps_dbg_printf(xhp, "%s: conf_file %s returned %d\n",
pkgname, entry_pname, rv); pkgname, entry_pname, rv);
return rv; return rv;

View File

@ -47,9 +47,8 @@
* state is XBPS_PKG_STATE_INSTALLED. * state is XBPS_PKG_STATE_INSTALLED.
*/ */
int int
xbps_configure_packages(bool flush) xbps_configure_packages(struct xbps_handle *xhp, bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_object_t obj; prop_object_t obj;
const char *pkgname; const char *pkgname;
size_t i; size_t i;
@ -61,23 +60,23 @@ xbps_configure_packages(bool flush)
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) { for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
obj = prop_array_get(xhp->pkgdb, i); obj = prop_array_get(xhp->pkgdb, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
rv = xbps_configure_pkg(pkgname, true, false, false); rv = xbps_configure_pkg(xhp, pkgname, true, false, false);
if (rv != 0) if (rv != 0)
break; break;
} }
if (flush) if (flush)
rv = xbps_pkgdb_update(true); rv = xbps_pkgdb_update(xhp, true);
return rv; return rv;
} }
int int
xbps_configure_pkg(const char *pkgname, xbps_configure_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool check_state, bool check_state,
bool update, bool update,
bool flush) bool flush)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
const char *version, *pkgver; const char *version, *pkgver;
char *buf; char *buf;
@ -85,9 +84,8 @@ xbps_configure_pkg(const char *pkgname,
pkg_state_t state = 0; pkg_state_t state = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
pkgd = xbps_pkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) if (pkgd == NULL)
return ENOENT; return ENOENT;
@ -96,9 +94,9 @@ xbps_configure_pkg(const char *pkgname,
if (check_state) { if (check_state) {
rv = xbps_pkg_state_dictionary(pkgd, &state); rv = xbps_pkg_state_dictionary(pkgd, &state);
xbps_dbg_printf("%s: state %d rv %d\n", pkgname, state, rv); xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgname, state, rv);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("%s: [configure] failed to get " xbps_dbg_printf(xhp, "%s: [configure] failed to get "
"pkg state: %s\n", pkgname, strerror(rv)); "pkg state: %s\n", pkgname, strerror(rv));
prop_object_release(pkgd); prop_object_release(pkgd);
return EINVAL; return EINVAL;
@ -115,7 +113,7 @@ xbps_configure_pkg(const char *pkgname,
} }
} }
prop_object_release(pkgd); prop_object_release(pkgd);
xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
buf = xbps_xasprintf("%s/metadata/%s/INSTALL", buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);
@ -123,8 +121,8 @@ xbps_configure_pkg(const char *pkgname,
return ENOMEM; return ENOMEM;
if (chdir(xhp->rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
pkgname, version, errno, pkgname, version,
"%s: [configure] failed to chdir to rootdir `%s': %s", "%s: [configure] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(errno)); pkgver, xhp->rootdir, strerror(errno));
free(buf); free(buf);
@ -132,11 +130,11 @@ xbps_configure_pkg(const char *pkgname,
} }
if (access(buf, X_OK) == 0) { if (access(buf, X_OK) == 0) {
if (xbps_file_exec(buf, "post", if (xbps_file_exec(xhp, buf, "post",
pkgname, version, update ? "yes" : "no", pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL) != 0) { xhp->conffile, NULL) != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
pkgname, version, errno, pkgname, version,
"%s: [configure] INSTALL script failed to execute " "%s: [configure] INSTALL script failed to execute "
"the post ACTION: %s", pkgver, strerror(errno)); "the post ACTION: %s", pkgver, strerror(errno));
free(buf); free(buf);
@ -144,8 +142,8 @@ xbps_configure_pkg(const char *pkgname,
} }
} else { } else {
if (errno != ENOENT) { if (errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
pkgname, version, errno, pkgname, version,
"%s: [configure] INSTALL script cannot be " "%s: [configure] INSTALL script cannot be "
"executed: %s", pkgver, strerror(errno)); "executed: %s", pkgver, strerror(errno));
free(buf); free(buf);
@ -153,17 +151,17 @@ xbps_configure_pkg(const char *pkgname,
} }
} }
free(buf); free(buf);
rv = xbps_set_pkg_state_installed(pkgname, version, rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_INSTALLED); XBPS_PKG_STATE_INSTALLED);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
pkgname, version, pkgname, version,
"%s: [configure] failed to set state to installed: %s", "%s: [configure] failed to set state to installed: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
} }
if (flush) { if (flush) {
if ((rv = xbps_pkgdb_update(true)) != 0) { if ((rv = xbps_pkgdb_update(xhp, true)) != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
pkgname, version, pkgname, version,
"%s: [configure] failed to update pkgdb: %s\n", "%s: [configure] failed to update pkgdb: %s\n",
pkgver, strerror(rv)); pkgver, strerror(rv));

View File

@ -52,7 +52,7 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
/* /*
* Check if current pkg conflicts with an installed package. * Check if current pkg conflicts with an installed package.
*/ */
if ((pkgd = xbps_pkgdb_get_pkgd(cfpkg, true))) { if ((pkgd = xbps_pkgdb_get_pkgd(xhp, cfpkg, true))) {
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver); "pkgver", &pkgver);
buf = xbps_xasprintf("%s conflicts with " buf = xbps_xasprintf("%s conflicts with "

View File

@ -65,7 +65,10 @@ struct orphan_data {
}; };
static int static int
find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done) find_orphan_pkg(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{ {
struct orphan_data *od = arg; struct orphan_data *od = arg;
prop_array_t reqby; prop_array_t reqby;
@ -79,6 +82,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
int rv = 0; int rv = 0;
pkg_state_t state; pkg_state_t state;
(void)xhp;
(void)loop_done; (void)loop_done;
/* /*
* Skip packages that were not installed automatically. * Skip packages that were not installed automatically.
@ -164,7 +168,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
} }
prop_array_t prop_array_t
xbps_find_pkg_orphans(prop_array_t orphans_user) xbps_find_pkg_orphans(struct xbps_handle *xhp, prop_array_t orphans_user)
{ {
prop_array_t array = NULL; prop_array_t array = NULL;
struct orphan_data od; struct orphan_data od;
@ -180,7 +184,7 @@ xbps_find_pkg_orphans(prop_array_t orphans_user)
* order in which packages were installed. * order in which packages were installed.
*/ */
od.orphans_user = orphans_user; od.orphans_user = orphans_user;
rv = xbps_pkgdb_foreach_reverse_cb(find_orphan_pkg, &od); rv = xbps_pkgdb_foreach_reverse_cb(xhp, find_orphan_pkg, &od);
if (rv != 0) { if (rv != 0) {
errno = rv; errno = rv;
prop_object_release(od.array); prop_object_release(od.array);

View File

@ -40,9 +40,8 @@
*/ */
int int
xbps_register_pkg(prop_dictionary_t pkgrd, bool flush) xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
prop_array_t provides, reqby; prop_array_t provides, reqby;
const char *pkgname, *version, *desc, *pkgver; const char *pkgname, *version, *desc, *pkgver;
@ -51,8 +50,6 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
xhp = xbps_handle_get();
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgrd, "version", &version); prop_dictionary_get_cstring_nocopy(pkgrd, "version", &version);
prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc);
@ -61,38 +58,42 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
provides = prop_dictionary_get(pkgrd, "provides"); provides = prop_dictionary_get(pkgrd, "provides");
reqby = prop_dictionary_get(pkgrd, "requiredby"); reqby = prop_dictionary_get(pkgrd, "requiredby");
xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
assert(desc != NULL); assert(desc != NULL);
assert(pkgver != NULL); assert(pkgver != NULL);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) { if (pkgd == NULL) {
rv = ENOENT; rv = ENOENT;
goto out; goto out;
} }
if (!prop_dictionary_set_cstring_nocopy(pkgd, if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version)) { "version", version)) {
xbps_dbg_printf("%s: invalid version for %s\n", __func__, pkgname); xbps_dbg_printf(xhp, "%s: invalid version for %s\n",
__func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (!prop_dictionary_set_cstring_nocopy(pkgd, if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgver", pkgver)) { "pkgver", pkgver)) {
xbps_dbg_printf("%s: invalid pkgver for %s\n", __func__, pkgname); xbps_dbg_printf(xhp, "%s: invalid pkgver for %s\n",
__func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (!prop_dictionary_set_cstring_nocopy(pkgd, if (!prop_dictionary_set_cstring_nocopy(pkgd,
"short_desc", desc)) { "short_desc", desc)) {
xbps_dbg_printf("%s: invalid short_desc for %s\n", __func__, pkgname); xbps_dbg_printf(xhp, "%s: invalid short_desc for %s\n",
__func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (reqby && !prop_dictionary_set(pkgd, "requiredby", reqby)) { if (reqby && !prop_dictionary_set(pkgd, "requiredby", reqby)) {
xbps_dbg_printf("%s: invalid requiredby for %s\n", __func__, pkgname); xbps_dbg_printf(xhp, "%s: invalid requiredby for %s\n",
__func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
@ -104,13 +105,15 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
if (!prop_dictionary_set_bool(pkgd, if (!prop_dictionary_set_bool(pkgd,
"automatic-install", autoinst)) { "automatic-install", autoinst)) {
xbps_dbg_printf("%s: invalid autoinst for %s\n", __func__, pkgname); xbps_dbg_printf(xhp, "%s: invalid autoinst for %s\n",
__func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (provides) { if (provides) {
if (!prop_dictionary_set(pkgd, "provides", provides)) { if (!prop_dictionary_set(pkgd, "provides", provides)) {
xbps_dbg_printf("%s: invalid provides for %s\n", xbps_dbg_printf(xhp,
"%s: invalid provides for %s\n",
__func__, pkgname); __func__, pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -121,13 +124,15 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
*/ */
if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) { if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) {
if ((rv = xbps_requiredby_pkg_add(xhp, pkgrd)) != 0) { if ((rv = xbps_requiredby_pkg_add(xhp, pkgrd)) != 0) {
xbps_dbg_printf("%s: requiredby add failed for %s\n", xbps_dbg_printf(xhp,
"%s: requiredby add failed for %s\n",
__func__, pkgname); __func__, pkgname);
goto out; goto out;
} }
} }
if (!xbps_pkgdb_replace_pkgd(pkgd, pkgname, false, flush)) { if (!xbps_pkgdb_replace_pkgd(xhp, pkgd, pkgname, false, flush)) {
xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n", xbps_dbg_printf(xhp,
"%s: failed to replace pkgd dict for %s\n",
__func__, pkgname); __func__, pkgname);
goto out; goto out;
} }
@ -136,7 +141,7 @@ out:
prop_object_release(pkgd); prop_object_release(pkgd);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REGISTER_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: failed to register package: %s", "%s: failed to register package: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -146,14 +151,17 @@ out:
} }
int int
xbps_unregister_pkg(const char *pkgname, const char *version, bool flush) xbps_unregister_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool flush)
{ {
assert(pkgname != NULL); assert(pkgname != NULL);
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
if (!xbps_pkgdb_remove_pkgd(pkgname, false, flush)) { if (!xbps_pkgdb_remove_pkgd(xhp, pkgname, false, flush)) {
xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: failed to unregister package: %s", "%s: failed to unregister package: %s",
pkgname, strerror(errno)); pkgname, strerror(errno));

View File

@ -74,10 +74,10 @@
* data type is specified on its edge, i.e string, array, integer, dictionary. * data type is specified on its edge, i.e string, array, integer, dictionary.
*/ */
static int static int
remove_pkg_metadata(const char *pkgname, remove_pkg_metadata(struct xbps_handle *xhp,
const char *pkgname,
const char *version, const char *version,
const char *pkgver, const char *pkgver)
const char *rootdir)
{ {
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
@ -85,9 +85,8 @@ remove_pkg_metadata(const char *pkgname,
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(rootdir != NULL);
metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir, metadir = xbps_xasprintf("%s/%s/metadata/%s", xhp->rootdir,
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);
if (metadir == NULL) if (metadir == NULL)
return ENOMEM; return ENOMEM;
@ -111,7 +110,7 @@ remove_pkg_metadata(const char *pkgname,
} }
if (unlink(path) == -1) { if (unlink(path) == -1) {
xbps_set_cb_state(XBPS_STATE_PURGE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_PURGE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [purge] failed to remove metafile `%s': %s", "%s: [purge] failed to remove metafile `%s': %s",
pkgver, path, strerror(errno)); pkgver, path, strerror(errno));
@ -128,11 +127,11 @@ remove_pkg_metadata(const char *pkgname,
} }
int int
xbps_remove_pkg_files(prop_dictionary_t dict, xbps_remove_pkg_files(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
const char *pkgver) const char *pkgver)
{ {
struct xbps_handle *xhp;
struct stat st; struct stat st;
prop_array_t array; prop_array_t array;
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -144,7 +143,6 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL); assert(key != NULL);
xhp = xbps_handle_get();
array = prop_dictionary_get(dict, key); array = prop_dictionary_get(dict, key);
if ((prop_object_type(array) != PROP_TYPE_ARRAY) || if ((prop_object_type(array) != PROP_TYPE_ARRAY) ||
@ -186,7 +184,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
rv = xbps_file_hash_check(path, sha256); rv = xbps_file_hash_check(path, sha256);
if (rv == ENOENT) { if (rv == ENOENT) {
/* missing file, ignore it */ /* missing file, ignore it */
xbps_set_cb_state( xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL, XBPS_STATE_REMOVE_FILE_HASH_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: failed to check hash for %s `%s': %s", "%s: failed to check hash for %s `%s': %s",
@ -198,7 +196,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
rv = 0; rv = 0;
if ((xhp->flags & if ((xhp->flags &
XBPS_FLAG_FORCE_REMOVE_FILES) == 0) { XBPS_FLAG_FORCE_REMOVE_FILES) == 0) {
xbps_set_cb_state( xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL, XBPS_STATE_REMOVE_FILE_HASH_FAIL,
0, pkgname, version, 0, pkgname, version,
"%s: %s `%s' SHA256 mismatch, " "%s: %s `%s' SHA256 mismatch, "
@ -207,7 +205,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
free(path); free(path);
continue; continue;
} else { } else {
xbps_set_cb_state( xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL, XBPS_STATE_REMOVE_FILE_HASH_FAIL,
0, pkgname, version, 0, pkgname, version,
"%s: %s `%s' SHA256 mismatch, " "%s: %s `%s' SHA256 mismatch, "
@ -215,7 +213,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
curobj, file); curobj, file);
} }
} else if (rv != 0 && rv != ERANGE) { } else if (rv != 0 && rv != ERANGE) {
xbps_set_cb_state( xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL, XBPS_STATE_REMOVE_FILE_HASH_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] failed to check hash for " "%s: [remove] failed to check hash for "
@ -245,14 +243,14 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
* Remove the object if possible. * Remove the object if possible.
*/ */
if (remove(path) == -1) { if (remove(path) == -1) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: failed to remove %s `%s': %s", pkgver, "%s: failed to remove %s `%s': %s", pkgver,
curobj, file, strerror(errno)); curobj, file, strerror(errno));
errno = 0; errno = 0;
} else { } else {
/* success */ /* success */
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
0, pkgname, version, 0, pkgname, version,
"Removed %s `%s'", curobj, file); "Removed %s `%s'", curobj, file);
} }
@ -266,10 +264,12 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
} }
int int
xbps_remove_pkg(const char *pkgname, const char *version, bool update, xbps_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool update,
bool soft_replace) bool soft_replace)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
char *buf = NULL, *pkgver = NULL; char *buf = NULL, *pkgver = NULL;
int rv = 0; int rv = 0;
@ -279,8 +279,6 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
xhp = xbps_handle_get();
buf = xbps_xasprintf("%s/metadata/%s/REMOVE", buf = xbps_xasprintf("%s/metadata/%s/REMOVE",
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);
if (buf == NULL) { if (buf == NULL) {
@ -294,15 +292,15 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
goto out; goto out;
} }
if ((rv = xbps_pkg_state_installed(pkgname, &state)) != 0) if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
goto out; goto out;
if (!update) if (!update)
xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
if (chdir(xhp->rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
rv = errno; rv = errno;
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] failed to chdir to rootdir `%s': %s", "%s: [remove] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(rv)); pkgver, xhp->rootdir, strerror(rv));
@ -316,9 +314,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
*/ */
if (access(buf, X_OK) == 0) { if (access(buf, X_OK) == 0) {
rmfile_exists = true; rmfile_exists = true;
if (xbps_file_exec(buf, "pre", pkgname, version, if (xbps_file_exec(xhp, buf, "pre", pkgname, version,
update ? "yes" : "no", xhp->conffile, NULL) != 0) { update ? "yes" : "no", xhp->conffile, NULL) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [remove] REMOVE script failed to " "%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s", "execute pre ACTION: %s",
@ -328,7 +326,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
} }
} else { } else {
if (errno != ENOENT) { if (errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [remove] REMOVE script failed to " "%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s", "execute pre ACTION: %s",
@ -345,7 +343,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
if (update) { if (update) {
free(pkgver); free(pkgver);
free(buf); free(buf);
return xbps_requiredby_pkg_remove(pkgname); return xbps_requiredby_pkg_remove(xhp, pkgname);
} else if (soft_replace) { } else if (soft_replace) {
/* /*
* Soft replace a package. Do not remove its files, but * Soft replace a package. Do not remove its files, but
@ -355,19 +353,19 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
goto softreplace; goto softreplace;
} }
pkgd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES); pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (pkgd) { if (pkgd) {
/* Remove regular files */ /* Remove regular files */
if ((rv = xbps_remove_pkg_files(pkgd, "files", pkgver)) != 0) if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
goto out; goto out;
/* Remove configuration files */ /* Remove configuration files */
if ((rv = xbps_remove_pkg_files(pkgd, "conf_files", pkgver)) != 0) if ((rv = xbps_remove_pkg_files(xhp, pkgd, "conf_files", pkgver)) != 0)
goto out; goto out;
/* Remove links */ /* Remove links */
if ((rv = xbps_remove_pkg_files(pkgd, "links", pkgver)) != 0) if ((rv = xbps_remove_pkg_files(xhp, pkgd, "links", pkgver)) != 0)
goto out; goto out;
/* Remove dirs */ /* Remove dirs */
if ((rv = xbps_remove_pkg_files(pkgd, "dirs", pkgver)) != 0) if ((rv = xbps_remove_pkg_files(xhp, pkgd, "dirs", pkgver)) != 0)
goto out; goto out;
} }
/* /*
@ -375,9 +373,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
* updating the package. * updating the package.
*/ */
if (rmfile_exists && if (rmfile_exists &&
((rv = xbps_file_exec(buf, "post", pkgname, version, "no", ((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no",
xhp->conffile, NULL)) != 0)) { xhp->conffile, NULL)) != 0)) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] REMOVE script failed to execute " "%s: [remove] REMOVE script failed to execute "
"post ACTION: %s", pkgver, strerror(rv)); "post ACTION: %s", pkgver, strerror(rv));
@ -386,8 +384,8 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
/* /*
* Update the requiredby array of all required dependencies. * Update the requiredby array of all required dependencies.
*/ */
if ((rv = xbps_requiredby_pkg_remove(pkgname)) != 0) { if ((rv = xbps_requiredby_pkg_remove(xhp, pkgname)) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] failed to remove requiredby entries: %s", "%s: [remove] failed to remove requiredby entries: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -398,10 +396,10 @@ softreplace:
/* /*
* Set package state to "half-removed". * Set package state to "half-removed".
*/ */
rv = xbps_set_pkg_state_installed(pkgname, version, rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_HALF_REMOVED); XBPS_PKG_STATE_HALF_REMOVED);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] failed to set state to half-removed: %s", "%s: [remove] failed to set state to half-removed: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -413,9 +411,9 @@ purge:
* Execute the purge REMOVE action if file exists. * Execute the purge REMOVE action if file exists.
*/ */
if (access(buf, X_OK) == 0) { if (access(buf, X_OK) == 0) {
if ((rv = xbps_file_exec(buf, "purge", pkgname, version, "no", if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no",
xhp->conffile, NULL)) != 0) { xhp->conffile, NULL)) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: REMOVE script failed to execute " "%s: REMOVE script failed to execute "
"purge ACTION: %s", pkgver, strerror(rv)); "purge ACTION: %s", pkgver, strerror(rv));
@ -425,9 +423,9 @@ purge:
/* /*
* Remove package metadata directory. * Remove package metadata directory.
*/ */
rv = remove_pkg_metadata(pkgname, version, pkgver, xhp->rootdir); rv = remove_pkg_metadata(xhp, pkgname, version, pkgver);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: failed to remove metadata files: %s", "%s: failed to remove metadata files: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -437,10 +435,10 @@ purge:
/* /*
* Unregister package from pkgdb. * Unregister package from pkgdb.
*/ */
if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0) if ((rv = xbps_unregister_pkg(xhp, pkgname, version, false)) != 0)
goto out; goto out;
xbps_set_cb_state(XBPS_STATE_REMOVE_DONE, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE,
0, pkgname, version, NULL); 0, pkgname, version, NULL);
out: out:

View File

@ -36,7 +36,8 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
int HIDDEN int HIDDEN
xbps_remove_obsoletes(const char *pkgname, xbps_remove_obsoletes(struct xbps_handle *xhp,
const char *pkgname,
const char *version, const char *version,
const char *pkgver, const char *pkgver,
prop_dictionary_t oldd, prop_dictionary_t oldd,
@ -131,14 +132,16 @@ again:
* Obsolete obj found, remove it. * Obsolete obj found, remove it.
*/ */
if (remove(file) == -1) { if (remove(file) == -1) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL, xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: failed to remove obsolete entry `%s': %s", "%s: failed to remove obsolete entry `%s': %s",
pkgver, file, strerror(errno)); pkgver, file, strerror(errno));
free(file); free(file);
continue; continue;
} }
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_OBSOLETE, xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_OBSOLETE,
0, pkgname, version, 0, pkgname, version,
"Removed obsolete entry: %s", file); "Removed obsolete entry: %s", file);
free(file); free(file);

View File

@ -32,7 +32,9 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
static int static int
add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver) add_pkg_into_reqby(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkgver)
{ {
prop_array_t reqby; prop_array_t reqby;
prop_string_t reqstr; prop_string_t reqstr;
@ -57,7 +59,7 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
if (xbps_match_pkgname_in_array(reqby, pkgname)) { if (xbps_match_pkgname_in_array(reqby, pkgname)) {
if (!xbps_remove_pkgname_from_array(reqby, pkgname)) { if (!xbps_remove_pkgname_from_array(reqby, pkgname)) {
xbps_dbg_printf("%s: failed to remove %s reqby entry: " xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: "
"%s\n", __func__, pkgname, strerror(errno)); "%s\n", __func__, pkgname, strerror(errno));
free(pkgname); free(pkgname);
return EINVAL; return EINVAL;
@ -95,11 +97,15 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
} }
static int static int
remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done) remove_pkg_from_reqby(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{ {
prop_array_t reqby; prop_array_t reqby;
const char *pkgname = arg; const char *pkgname = arg;
(void)xhp;
(void)loop_done; (void)loop_done;
reqby = prop_dictionary_get(obj, "requiredby"); reqby = prop_dictionary_get(obj, "requiredby");
@ -115,10 +121,10 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
} }
int HIDDEN int HIDDEN
xbps_requiredby_pkg_remove(const char *pkgname) xbps_requiredby_pkg_remove(struct xbps_handle *xhp, const char *pkgname)
{ {
assert(pkgname != NULL); assert(pkgname != NULL);
return xbps_pkgdb_foreach_cb(remove_pkg_from_reqby, __UNCONST(pkgname)); return xbps_pkgdb_foreach_cb(xhp, remove_pkg_from_reqby, __UNCONST(pkgname));
} }
int HIDDEN int HIDDEN
@ -147,10 +153,11 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
rv = EINVAL; rv = EINVAL;
break; break;
} }
xbps_dbg_printf("%s: adding reqby entry for %s\n", __func__, str); xbps_dbg_printf(xhp, "%s: adding reqby entry for %s\n",
__func__, str);
pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern( pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern(
xhp->pkgdb, str); xhp, xhp->pkgdb, str);
if (pkgd_pkgdb == NULL) { if (pkgd_pkgdb == NULL) {
pkgd_pkgdb = pkgd_pkgdb =
xbps_find_virtualpkg_in_array_by_pattern( xbps_find_virtualpkg_in_array_by_pattern(
@ -160,13 +167,14 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
xhp->pkgdb, str, NULL); xhp->pkgdb, str, NULL);
if (pkgd_pkgdb == NULL) { if (pkgd_pkgdb == NULL) {
rv = ENOENT; rv = ENOENT;
xbps_dbg_printf("%s: couldnt find `%s' " xbps_dbg_printf(xhp,
"%s: couldnt find `%s' "
"entry in pkgdb\n", __func__, str); "entry in pkgdb\n", __func__, str);
break; break;
} }
} }
} }
rv = add_pkg_into_reqby(pkgd_pkgdb, pkgver); rv = add_pkg_into_reqby(xhp, pkgd_pkgdb, pkgver);
if (rv != 0) if (rv != 0)
break; break;
} }

View File

@ -93,14 +93,16 @@ get_state(prop_dictionary_t dict)
} }
int int
xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state) xbps_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
pkg_state_t *state)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(state != NULL); assert(state != NULL);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) if (pkgd == NULL)
return ENOENT; return ENOENT;
@ -156,17 +158,16 @@ set_pkg_objs(prop_dictionary_t pkgd, const char *name, const char *version)
} }
int int
xbps_set_pkg_state_installed(const char *pkgname, xbps_set_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
const char *version, const char *version,
pkg_state_t state) pkg_state_t state)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
bool newpkg = false; bool newpkg = false;
int rv; int rv;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
if (xhp->pkgdb == NULL) { if (xhp->pkgdb == NULL) {
xhp->pkgdb = prop_array_create(); xhp->pkgdb = prop_array_create();
@ -198,7 +199,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
return EINVAL; return EINVAL;
} }
} else { } else {
pkgd = xbps_pkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) { if (pkgd == NULL) {
newpkg = true; newpkg = true;
pkgd = prop_dictionary_create(); pkgd = prop_dictionary_create();

View File

@ -49,7 +49,8 @@ set_extract_flags(void)
} }
static int static int
extract_metafile(struct archive *ar, extract_metafile(struct xbps_handle *xhp,
struct archive *ar,
struct archive_entry *entry, struct archive_entry *entry,
const char *file, const char *file,
const char *pkgver, const char *pkgver,
@ -85,7 +86,7 @@ extract_metafile(struct archive *ar,
dname = dirname(dirc); dname = dirname(dirc);
if (access(dname, X_OK) == -1) { if (access(dname, X_OK) == -1) {
if (xbps_mkpath(dname, 0755) == -1) { if (xbps_mkpath(dname, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to create metadir `%s': %s", "%s: [unpack] failed to create metadir `%s': %s",
pkgver, dname, strerror(errno)); pkgver, dname, strerror(errno));
@ -100,7 +101,7 @@ extract_metafile(struct archive *ar,
if (archive_read_extract(ar, entry, flags) != 0) { if (archive_read_extract(ar, entry, flags) != 0) {
rv = archive_errno(ar); rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to extract metafile `%s': %s", "%s: [unpack] failed to extract metafile `%s': %s",
pkgver, file, strerror(rv)); pkgver, file, strerror(rv));
@ -115,7 +116,9 @@ extract_metafile(struct archive *ar,
} }
static int static int
remove_metafile(const char *file, const char *pkgver) remove_metafile(struct xbps_handle *xhp,
const char *file,
const char *pkgver)
{ {
const char *version; const char *version;
char *buf, *pkgname; char *buf, *pkgname;
@ -136,7 +139,7 @@ remove_metafile(const char *file, const char *pkgver)
} }
if (unlink(buf) == -1) { if (unlink(buf) == -1) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to remove metafile `%s': %s", "%s: [unpack] failed to remove metafile `%s': %s",
pkgver, file, strerror(errno)); pkgver, file, strerror(errno));
@ -152,11 +155,12 @@ remove_metafile(const char *file, const char *pkgver)
} }
static int static int
unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar) unpack_archive(struct xbps_handle *xhp,
prop_dictionary_t pkg_repod,
struct archive *ar)
{ {
prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL; prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL;
prop_array_t array; prop_array_t array;
const struct xbps_handle *xhp = xbps_handle_get();
const struct stat *entry_statp; const struct stat *entry_statp;
struct stat st; struct stat st;
struct xbps_unpack_cb_data *xucd = NULL; struct xbps_unpack_cb_data *xucd = NULL;
@ -205,7 +209,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
} }
} }
if (chdir(xhp->rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to chdir to rootdir `%s': %s", "%s: [unpack] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(errno)); pkgver, xhp->rootdir, strerror(errno));
@ -218,9 +222,9 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
* Always remove current INSTALL/REMOVE scripts in pkg's metadir, * Always remove current INSTALL/REMOVE scripts in pkg's metadir,
* as security measures. * as security measures.
*/ */
if ((rv = remove_metafile("INSTALL", pkgver)) != 0) if ((rv = remove_metafile(xhp, "INSTALL", pkgver)) != 0)
goto out; goto out;
if ((rv = remove_metafile("REMOVE", pkgver)) != 0) if ((rv = remove_metafile(xhp, "REMOVE", pkgver)) != 0)
goto out; goto out;
/* /*
@ -263,18 +267,19 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;
} }
rv = extract_metafile(ar, entry, "INSTALL", rv = extract_metafile(xhp, ar, entry,
pkgver, true, flags); "INSTALL", pkgver, true, flags);
if (rv != 0) if (rv != 0)
goto out; goto out;
rv = xbps_file_exec(buf, "pre", rv = xbps_file_exec(xhp, buf, "pre",
pkgname, version, update ? "yes" : "no", pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL); xhp->conffile, NULL);
free(buf); free(buf);
buf = NULL; buf = NULL;
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] INSTALL script failed " "%s: [unpack] INSTALL script failed "
"to execute pre ACTION: %s", "to execute pre ACTION: %s",
@ -285,8 +290,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
continue; continue;
} else if (strcmp("./REMOVE", entry_pname) == 0) { } else if (strcmp("./REMOVE", entry_pname) == 0) {
rv = extract_metafile(ar, entry, "REMOVE", rv = extract_metafile(xhp, ar, entry,
pkgver, true, flags); "REMOVE", pkgver, true, flags);
if (rv != 0) if (rv != 0)
goto out; goto out;
@ -308,12 +313,12 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
continue; continue;
} else if (strcmp("./props.plist", entry_pname) == 0) { } else if (strcmp("./props.plist", entry_pname) == 0) {
rv = extract_metafile(ar, entry, XBPS_PKGPROPS, rv = extract_metafile(xhp, ar, entry, XBPS_PKGPROPS,
pkgver, false, flags); pkgver, false, flags);
if (rv != 0) if (rv != 0)
goto out; goto out;
propsd = xbps_dictionary_from_metadata_plist( propsd = xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS); pkgname, XBPS_PKGPROPS);
if (propsd == NULL) { if (propsd == NULL) {
rv = errno; rv = errno;
@ -334,7 +339,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
* This is not an XBPS binary package. * This is not an XBPS binary package.
*/ */
if (entry_idx >= 3) { if (entry_idx >= 3) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL,
ENODEV, pkgname, version, ENODEV, pkgname, version,
"%s: [unpack] invalid binary package `%s'.", "%s: [unpack] invalid binary package `%s'.",
pkgver, fname); pkgver, fname);
@ -379,13 +385,14 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
buf[x] = entry_pname[i]; buf[x] = entry_pname[i];
buf[x] = '\0'; buf[x] = '\0';
file_exists = true; file_exists = true;
rv = xbps_file_hash_check_dictionary(filesd, rv = xbps_file_hash_check_dictionary(xhp, filesd,
conf_file ? "conf_files" : "files", buf); conf_file ? "conf_files" : "files", buf);
free(buf); free(buf);
if (rv == -1) { if (rv == -1) {
/* error */ /* error */
xbps_dbg_printf("%s-%s: failed to check" xbps_dbg_printf(xhp,
"%s-%s: failed to check"
" hash for `%s': %s\n", pkgname, " hash for `%s': %s\n", pkgname,
version, entry_pname, version, entry_pname,
strerror(errno)); strerror(errno));
@ -397,7 +404,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/ */
if (chmod(entry_pname, if (chmod(entry_pname,
entry_statp->st_mode) != 0) { entry_statp->st_mode) != 0) {
xbps_dbg_printf("%s-%s: failed " xbps_dbg_printf(xhp,
"%s-%s: failed "
"to set perms %s to %s: %s\n", "to set perms %s to %s: %s\n",
pkgname, version, pkgname, version,
archive_entry_strmode(entry), archive_entry_strmode(entry),
@ -406,14 +414,16 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
xbps_dbg_printf("%s-%s: entry %s perms " xbps_dbg_printf(xhp,
"%s-%s: entry %s perms "
"to %s.\n", pkgname, version, "to %s.\n", pkgname, version,
entry_pname, entry_pname,
archive_entry_strmode(entry)); archive_entry_strmode(entry));
/* /*
* hash match, skip extraction. * hash match, skip extraction.
*/ */
xbps_dbg_printf("%s-%s: entry %s " xbps_dbg_printf(xhp,
"%s-%s: entry %s "
"matches current SHA256, " "matches current SHA256, "
"skipping...\n", pkgname, "skipping...\n", pkgname,
version, entry_pname); version, entry_pname);
@ -435,7 +445,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
(void)rename(entry_pname, buf); (void)rename(entry_pname, buf);
free(buf); free(buf);
buf = NULL; buf = NULL;
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, 0, xbps_set_cb_state(xhp,
XBPS_STATE_CONFIG_FILE, 0,
pkgname, version, pkgname, version,
"Renamed old configuration file " "Renamed old configuration file "
"`%s' to `%s.old'.", entry_pname, entry_pname); "`%s' to `%s.old'.", entry_pname, entry_pname);
@ -449,7 +460,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
if (xucd != NULL) if (xucd != NULL)
xucd->entry_is_conf = true; xucd->entry_is_conf = true;
rv = xbps_entry_install_conf_file(filesd, rv = xbps_entry_install_conf_file(xhp, filesd,
entry, entry_pname, pkgname, version); entry, entry_pname, pkgname, version);
if (rv == -1) { if (rv == -1) {
/* error */ /* error */
@ -468,21 +479,21 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/ */
if (archive_read_extract(ar, entry, flags) != 0) { if (archive_read_extract(ar, entry, flags) != 0) {
rv = archive_errno(ar); rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to extract file `%s': %s", "%s: [unpack] failed to extract file `%s': %s",
pkgver, entry_pname, strerror(rv)); pkgver, entry_pname, strerror(rv));
} }
if (xucd != NULL) { if (xucd != NULL) {
xucd->entry_extract_count++; xucd->entry_extract_count++;
(*xhp->unpack_cb)(xucd, xhp->unpack_cb_data); (*xhp->unpack_cb)(xhp, xucd, xhp->unpack_cb_data);
} }
} }
/* /*
* If there was any error extracting files from archive, error out. * If there was any error extracting files from archive, error out.
*/ */
if ((rv = archive_errno(ar)) != 0) { if ((rv = archive_errno(ar)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to extract files: %s", "%s: [unpack] failed to extract files: %s",
pkgver, fname, archive_error_string(ar)); pkgver, fname, archive_error_string(ar));
@ -509,7 +520,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/ */
old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd); old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd);
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) { if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
rv = xbps_remove_obsoletes(pkgname, version, rv = xbps_remove_obsoletes(xhp, pkgname, version,
pkgver, old_filesd, filesd); pkgver, old_filesd, filesd);
prop_object_release(old_filesd); prop_object_release(old_filesd);
if (rv != 0) { if (rv != 0) {
@ -530,7 +541,7 @@ out1:
goto out; goto out;
} }
if (xbps_mkpath(buf, 0755) == -1) { if (xbps_mkpath(buf, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to create pkg metadir `%s': %s", "%s: [unpack] failed to create pkg metadir `%s': %s",
buf, pkgver, strerror(errno)); buf, pkgver, strerror(errno));
@ -542,7 +553,7 @@ out1:
*/ */
if (!prop_dictionary_externalize_to_zfile(filesd, pkgfilesd)) { if (!prop_dictionary_externalize_to_zfile(filesd, pkgfilesd)) {
rv = errno; rv = errno;
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to extract metadata file `%s': %s", "%s: [unpack] failed to extract metadata file `%s': %s",
pkgver, XBPS_PKGFILES, strerror(errno)); pkgver, XBPS_PKGFILES, strerror(errno));
@ -564,7 +575,7 @@ out:
} }
int HIDDEN int HIDDEN
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
{ {
struct archive *ar = NULL; struct archive *ar = NULL;
const char *pkgname, *version, *repoloc, *pkgver, *fname; const char *pkgname, *version, *repoloc, *pkgver, *fname;
@ -579,11 +590,11 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname); prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
xbps_set_cb_state(XBPS_STATE_UNPACK, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc); bpkg = xbps_path_from_repository_uri(xhp, pkg_repod, repoloc);
if (bpkg == NULL) { if (bpkg == NULL) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] cannot determine binary package " "%s: [unpack] cannot determine binary package "
"file for `%s': %s", pkgver, fname, strerror(errno)); "file for `%s': %s", pkgver, fname, strerror(errno));
@ -604,7 +615,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
if (archive_read_open_filename(ar, bpkg, ARCHIVE_READ_BLOCKSIZE) != 0) { if (archive_read_open_filename(ar, bpkg, ARCHIVE_READ_BLOCKSIZE) != 0) {
rv = archive_errno(ar); rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to open binary package `%s': %s", "%s: [unpack] failed to open binary package `%s': %s",
pkgver, fname, strerror(rv)); pkgver, fname, strerror(rv));
@ -617,9 +628,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Set package state to half-unpacked. * Set package state to half-unpacked.
*/ */
if ((rv = xbps_set_pkg_state_installed(pkgname, version, if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_HALF_UNPACKED)) != 0) { XBPS_PKG_STATE_HALF_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to set state to half-unpacked: %s", "%s: [unpack] failed to set state to half-unpacked: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -628,8 +639,8 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Extract archive files. * Extract archive files.
*/ */
if ((rv = unpack_archive(pkg_repod, ar)) != 0) { if ((rv = unpack_archive(xhp, pkg_repod, ar)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to unpack files from archive: %s", "%s: [unpack] failed to unpack files from archive: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
@ -638,9 +649,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Set package state to unpacked. * Set package state to unpacked.
*/ */
if ((rv = xbps_set_pkg_state_installed(pkgname, version, if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_UNPACKED)) != 0) { XBPS_PKG_STATE_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to set state to unpacked: %s", "%s: [unpack] failed to set state to unpacked: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));

View File

@ -64,22 +64,21 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
if (xhp->pkgdb != NULL) if (xhp->pkgdb != NULL)
return 0; return 0;
if ((rv = xbps_pkgdb_update(false)) != 0) { if ((rv = xbps_pkgdb_update(xhp, false)) != 0) {
if (rv != ENOENT) if (rv != ENOENT)
xbps_dbg_printf("[pkgdb] cannot internalize " xbps_dbg_printf(xhp, "[pkgdb] cannot internalize "
"pkgdb array: %s\n", strerror(rv)); "pkgdb array: %s\n", strerror(rv));
return rv; return rv;
} }
xbps_dbg_printf("[pkgdb] initialized ok.\n"); xbps_dbg_printf(xhp, "[pkgdb] initialized ok.\n");
return 0; return 0;
} }
int int
xbps_pkgdb_update(bool flush) xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
char *plist; char *plist;
int rv = 0; int rv = 0;
@ -92,7 +91,8 @@ xbps_pkgdb_update(bool flush)
if (access(xhp->metadir, X_OK) == -1) { if (access(xhp->metadir, X_OK) == -1) {
if (errno == ENOENT) { if (errno == ENOENT) {
if (xbps_mkpath(xhp->metadir, 0755) != 0) { if (xbps_mkpath(xhp->metadir, 0755) != 0) {
xbps_dbg_printf("[pkgdb] failed to " xbps_dbg_printf(xhp,
"[pkgdb] failed to "
"create metadir %s: %s\n", "create metadir %s: %s\n",
xhp->metadir, xhp->metadir,
strerror(errno)); strerror(errno));
@ -133,46 +133,47 @@ xbps_pkgdb_release(struct xbps_handle *xhp)
prop_object_release(xhp->pkgdb); prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL; xhp->pkgdb = NULL;
xbps_dbg_printf("[pkgdb] released ok.\n"); xbps_dbg_printf(xhp, "[pkgdb] released ok.\n");
} }
static int static int
foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), foreach_pkg_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg, void *arg,
bool reverse) bool reverse)
{ {
struct xbps_handle *xhp = xbps_handle_get();
int rv; int rv;
if ((rv = xbps_pkgdb_init(xhp)) != 0) if ((rv = xbps_pkgdb_init(xhp)) != 0)
return rv; return rv;
if (reverse) if (reverse)
rv = xbps_callback_array_iter_reverse(xhp->pkgdb, fn, arg); rv = xbps_callback_array_iter_reverse(xhp, xhp->pkgdb, fn, arg);
else else
rv = xbps_callback_array_iter(xhp->pkgdb, fn, arg); rv = xbps_callback_array_iter(xhp, xhp->pkgdb, fn, arg);
return rv; return rv;
} }
int int
xbps_pkgdb_foreach_reverse_cb(int (*fn)(prop_object_t, void *, bool *), xbps_pkgdb_foreach_reverse_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
return foreach_pkg_cb(fn, arg, true); return foreach_pkg_cb(xhp, fn, arg, true);
} }
int int
xbps_pkgdb_foreach_cb(int (*fn)(prop_object_t, void *, bool *), xbps_pkgdb_foreach_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
return foreach_pkg_cb(fn, arg, false); return foreach_pkg_cb(xhp, fn, arg, false);
} }
prop_dictionary_t prop_dictionary_t
xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern) xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
if (xbps_pkgdb_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
@ -190,9 +191,8 @@ xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern)
} }
prop_dictionary_t prop_dictionary_t
xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver) xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
if (xbps_pkgdb_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
@ -206,9 +206,11 @@ xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver)
} }
bool bool
xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush) xbps_pkgdb_remove_pkgd(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
bool rv = false; bool rv = false;
if (xbps_pkgdb_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
@ -222,19 +224,19 @@ xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush)
if (!flush || !rv) if (!flush || !rv)
return rv; return rv;
if ((xbps_pkgdb_update(true)) != 0) if ((xbps_pkgdb_update(xhp, true)) != 0)
return false; return false;
return true; return true;
} }
bool bool
xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd, xbps_pkgdb_replace_pkgd(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkg, const char *pkg,
bool bypattern, bool bypattern,
bool flush) bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
int rv; int rv;
if (xbps_pkgdb_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
@ -248,7 +250,7 @@ xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
if (!flush) if (!flush)
return rv != 0 ? false : true; return rv != 0 ? false : true;
if ((xbps_pkgdb_update(true)) != 0) if ((xbps_pkgdb_update(xhp, true)) != 0)
return false; return false;
return true; return true;

View File

@ -74,8 +74,9 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
} }
int int
xbps_callback_array_iter(prop_array_t array, xbps_callback_array_iter(struct xbps_handle *xhp,
int (*fn)(prop_object_t, void *, bool *), prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
prop_object_t obj; prop_object_t obj;
@ -91,7 +92,7 @@ xbps_callback_array_iter(prop_array_t array,
return ENOMEM; return ENOMEM;
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
rv = (*fn)(obj, arg, &loop_done); rv = (*fn)(xhp, obj, arg, &loop_done);
if (rv != 0 || loop_done) if (rv != 0 || loop_done)
break; break;
} }
@ -101,9 +102,10 @@ xbps_callback_array_iter(prop_array_t array,
} }
int int
xbps_callback_array_iter_in_dict(prop_dictionary_t dict, xbps_callback_array_iter_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
prop_object_t obj; prop_object_t obj;
@ -113,6 +115,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
bool cbloop_done = false; bool cbloop_done = false;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(xhp != NULL);
assert(key != NULL); assert(key != NULL);
assert(fn != NULL); assert(fn != NULL);
@ -124,7 +127,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
obj = prop_array_get(array, i); obj = prop_array_get(array, i);
if (obj == NULL) if (obj == NULL)
continue; continue;
rv = (*fn)(obj, arg, &cbloop_done); rv = (*fn)(xhp, obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done) if (rv != 0 || cbloop_done)
break; break;
} }
@ -133,8 +136,9 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
} }
int int
xbps_callback_array_iter_reverse(prop_array_t array, xbps_callback_array_iter_reverse(struct xbps_handle *xhp,
int (*fn)(prop_object_t, void *, bool *), prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
prop_object_t obj; prop_object_t obj;
@ -144,6 +148,7 @@ xbps_callback_array_iter_reverse(prop_array_t array,
assert(prop_object_type(array) == PROP_TYPE_ARRAY); assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(fn != NULL); assert(fn != NULL);
assert(xhp != NULL);
if ((cnt = prop_array_count(array)) == 0) if ((cnt = prop_array_count(array)) == 0)
return 0; return 0;
@ -152,7 +157,7 @@ xbps_callback_array_iter_reverse(prop_array_t array,
obj = prop_array_get(array, cnt); obj = prop_array_get(array, cnt);
if (obj == NULL) if (obj == NULL)
continue; continue;
rv = (*fn)(obj, arg, &loop_done); rv = (*fn)(xhp, obj, arg, &loop_done);
if (rv != 0 || loop_done) if (rv != 0 || loop_done)
break; break;
} }
@ -161,9 +166,10 @@ xbps_callback_array_iter_reverse(prop_array_t array,
} }
int int
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, xbps_callback_array_iter_reverse_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
prop_array_t array; prop_array_t array;
@ -171,14 +177,15 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL); assert(key != NULL);
assert(fn != NULL); assert(fn != NULL);
assert(xhp != NULL);
array = prop_dictionary_get(dict, key); array = prop_dictionary_get(dict, key);
if (prop_object_type(array) != PROP_TYPE_ARRAY) { if (prop_object_type(array) != PROP_TYPE_ARRAY) {
xbps_dbg_printf("invalid key '%s' for dictionary", key); xbps_dbg_printf(xhp, "invalid key '%s' for dictionary", key);
return EINVAL; return EINVAL;
} }
return xbps_callback_array_iter_reverse(array, fn, arg); return xbps_callback_array_iter_reverse(xhp, array, fn, arg);
} }
prop_object_iterator_t prop_object_iterator_t
@ -259,17 +266,16 @@ xbps_array_replace_dict_by_pattern(prop_array_t array,
} }
prop_dictionary_t prop_dictionary_t
xbps_dictionary_from_metadata_plist(const char *pkgname, xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
const char *pkgname,
const char *plist) const char *plist)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd, plistd = NULL; prop_dictionary_t pkgd, plistd = NULL;
const char *savedpkgname; const char *savedpkgname;
char *plistf; char *plistf;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(plist != NULL); assert(plist != NULL);
xhp = xbps_handle_get();
savedpkgname = pkgname; savedpkgname = pkgname;
plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir, plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
@ -278,9 +284,9 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
return NULL; return NULL;
if (access(plistf, R_OK) == -1) { if (access(plistf, R_OK) == -1) {
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false); pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false);
if (pkgd == NULL) if (pkgd == NULL)
pkgd = xbps_find_pkg_dict_installed(pkgname, false); pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (pkgd != NULL) { if (pkgd != NULL) {
free(plistf); free(plistf);
@ -297,7 +303,7 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
plistd = prop_dictionary_internalize_from_zfile(plistf); plistd = prop_dictionary_internalize_from_zfile(plistf);
free(plistf); free(plistf);
if (plistd == NULL) { if (plistd == NULL) {
xbps_dbg_printf("cannot read from metadata %s for %s: %s\n", xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n",
plist, savedpkgname, strerror(errno)); plist, savedpkgname, strerror(errno));
return NULL; return NULL;
} }

View File

@ -52,8 +52,6 @@ fetch_archive_open(struct archive *a, void *client_data)
(void)a; (void)a;
xbps_dbg_printf("%s: establishing connection to `%s'...\n",
__func__, f->url->host);
f->fetch = fetchGet(f->url, NULL); f->fetch = fetchGet(f->url, NULL);
if (f->fetch == NULL) if (f->fetch == NULL)
return ENOENT; return ENOENT;
@ -69,9 +67,6 @@ fetch_archive_read(struct archive *a, void *client_data, const void **buf)
(void)a; (void)a;
*buf = f->buffer; *buf = f->buffer;
xbps_dbg_printf("%s: fetching data from `%s'...\n",
__func__, f->url->doc);
return fetchIO_read(f->fetch, f->buffer, sizeof(f->buffer)); return fetchIO_read(f->fetch, f->buffer, sizeof(f->buffer));
} }
@ -82,11 +77,8 @@ fetch_archive_close(struct archive *a, void *client_data)
(void)a; (void)a;
if (f->fetch != NULL) { if (f->fetch != NULL)
xbps_dbg_printf("%s: closing connection to `%s'...\n",
__func__, f->url->host);
fetchIO_close(f->fetch); fetchIO_close(f->fetch);
}
free(f); free(f);
return 0; return 0;

View File

@ -161,14 +161,14 @@ xbps_find_virtualpkg_in_array_by_pattern(prop_array_t array, const char *pattern
} }
static const char * static const char *
find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern) find_virtualpkg_user_in_conf(struct xbps_handle *xhp,
const char *vpkg,
bool bypattern)
{ {
const struct xbps_handle *xhp;
const char *vpkgver, *pkg = NULL; const char *vpkgver, *pkg = NULL;
char *vpkgname = NULL, *tmp; char *vpkgname = NULL, *tmp;
size_t i, j, cnt; size_t i, j, cnt;
xhp = xbps_handle_get();
if (xhp->cfg == NULL) if (xhp->cfg == NULL)
return NULL; return NULL;
@ -205,7 +205,8 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
} }
/* virtual package matched in conffile */ /* virtual package matched in conffile */
pkg = cfg_title(sec); pkg = cfg_title(sec);
xbps_dbg_printf("matched vpkg in conf `%s' for %s\n", xbps_dbg_printf(xhp,
"matched vpkg in conf `%s' for %s\n",
pkg, vpkg); pkg, vpkg);
free(vpkgname); free(vpkgname);
break; break;
@ -215,7 +216,8 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
} }
static prop_dictionary_t static prop_dictionary_t
find_virtualpkg_user_in_array(prop_array_t array, find_virtualpkg_user_in_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str, const char *str,
bool bypattern) bool bypattern)
{ {
@ -224,7 +226,7 @@ find_virtualpkg_user_in_array(prop_array_t array,
assert(prop_object_type(array) == PROP_TYPE_ARRAY); assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(str != NULL); assert(str != NULL);
vpkgname = find_virtualpkg_user_in_conf(str, bypattern); vpkgname = find_virtualpkg_user_in_conf(xhp, str, bypattern);
if (vpkgname == NULL) if (vpkgname == NULL)
return NULL; return NULL;
@ -232,15 +234,19 @@ find_virtualpkg_user_in_array(prop_array_t array,
} }
prop_dictionary_t HIDDEN prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_name(prop_array_t array, const char *name) xbps_find_virtualpkg_conf_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name)
{ {
return find_virtualpkg_user_in_array(array, name, false); return find_virtualpkg_user_in_array(xhp, array, name, false);
} }
prop_dictionary_t HIDDEN prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t array, const char *p) xbps_find_virtualpkg_conf_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *p)
{ {
return find_virtualpkg_user_in_array(array, p, true); return find_virtualpkg_user_in_array(xhp, array, p, true);
} }
static prop_dictionary_t static prop_dictionary_t
@ -314,19 +320,20 @@ xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d,
} }
static prop_dictionary_t static prop_dictionary_t
find_pkgd_installed(const char *str, bool bypattern, bool virtual) find_pkgd_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern,
bool virtual)
{ {
struct xbps_handle *xhp;
prop_dictionary_t pkgd, rpkgd = NULL; prop_dictionary_t pkgd, rpkgd = NULL;
pkg_state_t state = 0; pkg_state_t state = 0;
int rv; int rv;
assert(str != NULL); assert(str != NULL);
xhp = xbps_handle_get();
if ((rv = xbps_pkgdb_init(xhp)) != 0) { if ((rv = xbps_pkgdb_init(xhp)) != 0) {
if (rv != ENOENT) { if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize " xbps_dbg_printf(xhp, "%s: couldn't initialize "
"pkgdb: %s\n", strerror(rv)); "pkgdb: %s\n", strerror(rv));
return NULL; return NULL;
} else if (rv == ENOENT) } else if (rv == ENOENT)
@ -339,7 +346,7 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
find_pkg_in_array(xhp->pkgdb, str, bypattern, false, NULL); find_pkg_in_array(xhp->pkgdb, str, bypattern, false, NULL);
} else { } else {
/* virtual pkg set by user in conf */ /* virtual pkg set by user in conf */
pkgd = find_virtualpkg_user_in_array(xhp->pkgdb, pkgd = find_virtualpkg_user_in_array(xhp, xhp->pkgdb,
str, bypattern); str, bypattern);
if (pkgd == NULL) { if (pkgd == NULL) {
/* any virtual pkg in array matching pattern */ /* any virtual pkg in array matching pattern */
@ -369,13 +376,17 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_dict_installed(const char *str, bool bypattern) xbps_find_pkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern)
{ {
return find_pkgd_installed(str, bypattern, false); return find_pkgd_installed(xhp, str, bypattern, false);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_virtualpkg_dict_installed(const char *str, bool bypattern) xbps_find_virtualpkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern)
{ {
return find_pkgd_installed(str, bypattern, true); return find_pkgd_installed(xhp, str, bypattern, true);
} }

View File

@ -31,12 +31,12 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
static int static int
store_dependency(prop_array_t transd_unsorted, store_dependency(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd, prop_dictionary_t repo_pkgd,
pkg_state_t repo_pkg_state, pkg_state_t repo_pkg_state,
size_t *depth) size_t *depth)
{ {
const struct xbps_handle *xhp = xbps_handle_get(); prop_array_t unsorted;
int rv; int rv;
/* /*
* Overwrite package state in dictionary with same state than the * Overwrite package state in dictionary with same state than the
@ -52,7 +52,8 @@ store_dependency(prop_array_t transd_unsorted,
/* /*
* Add the dictionary into the array. * Add the dictionary into the array.
*/ */
if (!prop_array_add(transd_unsorted, repo_pkgd)) unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (!prop_array_add(unsorted, repo_pkgd))
return EINVAL; return EINVAL;
if (xhp->flags & XBPS_FLAG_DEBUG) { if (xhp->flags & XBPS_FLAG_DEBUG) {
@ -63,19 +64,20 @@ store_dependency(prop_array_t transd_unsorted,
"repository", &repo); "repository", &repo);
prop_dictionary_get_cstring_nocopy(repo_pkgd, prop_dictionary_get_cstring_nocopy(repo_pkgd,
"pkgver", &pkgver); "pkgver", &pkgver);
xbps_dbg_printf(" "); xbps_dbg_printf(xhp, " ");
for (x = 0; x < *depth; x++) for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" "); xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append("%s: added into " xbps_dbg_printf_append(xhp, "%s: added into "
"the transaction (%s).\n", pkgver, repo); "the transaction (%s).\n", pkgver, repo);
} }
return 0; return 0;
} }
static int static int
add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg) add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
{ {
prop_array_t mdeps;
prop_string_t reqpkg_str; prop_string_t reqpkg_str;
prop_object_iterator_t iter = NULL; prop_object_iterator_t iter = NULL;
prop_object_t obj; prop_object_t obj;
@ -83,16 +85,16 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
bool add_pkgdep, pkgfound, update_pkgdep; bool add_pkgdep, pkgfound, update_pkgdep;
int rv = 0; int rv = 0;
assert(prop_object_type(missing_rdeps) == PROP_TYPE_ARRAY);
assert(reqpkg != NULL); assert(reqpkg != NULL);
add_pkgdep = update_pkgdep = pkgfound = false; add_pkgdep = update_pkgdep = pkgfound = false;
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
reqpkg_str = prop_string_create_cstring_nocopy(reqpkg); reqpkg_str = prop_string_create_cstring_nocopy(reqpkg);
if (reqpkg_str == NULL) if (reqpkg_str == NULL)
return errno; return errno;
iter = prop_array_iterator(missing_rdeps); iter = prop_array_iterator(mdeps);
if (iter == NULL) if (iter == NULL)
goto out; goto out;
@ -126,7 +128,7 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
* if new dependency version is greater than current * if new dependency version is greater than current
* one, store it. * one, store it.
*/ */
xbps_dbg_printf("Missing pkgdep name matched, " xbps_dbg_printf(xhp, "Missing pkgdep name matched, "
"curver: %s newver: %s\n", curver, pkgver); "curver: %s newver: %s\n", curver, pkgver);
if (xbps_cmpver(curver, pkgver) <= 0) { if (xbps_cmpver(curver, pkgver) <= 0) {
add_pkgdep = false; add_pkgdep = false;
@ -149,8 +151,8 @@ out:
if (iter) if (iter)
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
if (update_pkgdep) if (update_pkgdep)
prop_array_remove(missing_rdeps, idx); prop_array_remove(mdeps, idx);
if (add_pkgdep && !xbps_add_obj_to_array(missing_rdeps, reqpkg_str)) { if (add_pkgdep && !xbps_add_obj_to_array(mdeps, reqpkg_str)) {
prop_object_release(reqpkg_str); prop_object_release(reqpkg_str);
return errno; return errno;
} }
@ -161,13 +163,11 @@ out:
#define MAX_DEPTH 512 #define MAX_DEPTH 512
static int static int
find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ find_repo_deps(struct xbps_handle *xhp,
prop_array_t trans_mdeps, /* transaction missing deps array */
prop_array_t pkg_rdeps_array, /* current pkg rundeps array */ prop_array_t pkg_rdeps_array, /* current pkg rundeps array */
const char *curpkg, /* current pkgver */ const char *curpkg, /* current pkgver */
size_t *depth) /* max recursion depth */ size_t *depth) /* max recursion depth */
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t curpkgd, tmpd; prop_dictionary_t curpkgd, tmpd;
prop_array_t curpkgrdeps, unsorted; prop_array_t curpkgrdeps, unsorted;
pkg_state_t state; pkg_state_t state;
@ -186,11 +186,11 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) { for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) {
prop_array_get_cstring_nocopy(pkg_rdeps_array, i, &reqpkg); prop_array_get_cstring_nocopy(pkg_rdeps_array, i, &reqpkg);
if (xhp->flags & XBPS_FLAG_DEBUG) { if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf(""); xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++) for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" "); xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append("%s: requires dependency '%s': ", xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ",
curpkg ? curpkg : " ", reqpkg); curpkg != NULL ? curpkg : " ", reqpkg);
} }
/* /*
* Pass 1: check if required dependency is already installed * Pass 1: check if required dependency is already installed
@ -198,19 +198,19 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
*/ */
if ((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) { if ((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) {
rv = EINVAL; rv = EINVAL;
xbps_dbg_printf("failed to get " xbps_dbg_printf(xhp, "failed to get "
"pkgname from `%s'!", reqpkg); "pkgname from `%s'!", reqpkg);
break; break;
} }
/* /*
* Look for a real package installed... * Look for a real package installed...
*/ */
tmpd = xbps_find_pkg_dict_installed(pkgname, false); tmpd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (tmpd == NULL) { if (tmpd == NULL) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
/* error */ /* error */
rv = errno; rv = errno;
xbps_dbg_printf("failed to find " xbps_dbg_printf(xhp, "failed to find "
"installed pkg for `%s': %s\n", "installed pkg for `%s': %s\n",
reqpkg, strerror(errno)); reqpkg, strerror(errno));
break; break;
@ -219,20 +219,21 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* real package not installed, try looking for * real package not installed, try looking for
* a virtual package instead. * a virtual package instead.
*/ */
tmpd = xbps_find_virtualpkg_dict_installed(pkgname, false); tmpd = xbps_find_virtualpkg_dict_installed(xhp,
pkgname, false);
} }
free(pkgname); free(pkgname);
if (tmpd == NULL) { if (tmpd == NULL) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
/* error */ /* error */
rv = errno; rv = errno;
xbps_dbg_printf("failed to find " xbps_dbg_printf(xhp, "failed to find "
"installed virtual pkg for `%s': %s\n", "installed virtual pkg for `%s': %s\n",
reqpkg, strerror(errno)); reqpkg, strerror(errno));
break; break;
} }
/* Required pkgdep not installed */ /* Required pkgdep not installed */
xbps_dbg_printf_append("not installed. "); xbps_dbg_printf_append(xhp, "not installed. ");
reason = "install"; reason = "install";
state = XBPS_PKG_STATE_NOT_INSTALLED; state = XBPS_PKG_STATE_NOT_INSTALLED;
} else { } else {
@ -255,7 +256,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* package and is satisfied by an * package and is satisfied by an
* installed package. * installed package.
*/ */
xbps_dbg_printf_append("[virtual] satisfied by " xbps_dbg_printf_append(xhp,
"[virtual] satisfied by "
"`%s'.\n", pkgver_q); "`%s'.\n", pkgver_q);
prop_object_release(tmpd); prop_object_release(tmpd);
continue; continue;
@ -266,7 +268,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is installed but does not match * Package is installed but does not match
* the dependency pattern, update pkg. * the dependency pattern, update pkg.
*/ */
xbps_dbg_printf_append("installed `%s', " xbps_dbg_printf_append(xhp,
"installed `%s', "
"must be updated.\n", pkgver_q); "must be updated.\n", pkgver_q);
reason = "update"; reason = "update";
} else if (rv == 1) { } else if (rv == 1) {
@ -277,7 +280,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern but was only unpacked, * pattern but was only unpacked,
* configure pkg. * configure pkg.
*/ */
xbps_dbg_printf_append("installed `%s'" xbps_dbg_printf_append(xhp,
"installed `%s'"
", must be configured.\n", ", must be configured.\n",
pkgver_q); pkgver_q);
reason = "configure"; reason = "configure";
@ -287,7 +291,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern and is fully installed, * pattern and is fully installed,
* skip to next one. * skip to next one.
*/ */
xbps_dbg_printf_append("installed " xbps_dbg_printf_append(xhp,
"installed "
"`%s'.\n", pkgver_q); "`%s'.\n", pkgver_q);
prop_object_release(tmpd); prop_object_release(tmpd);
continue; continue;
@ -295,7 +300,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else { } else {
/* error matching pkgpattern */ /* error matching pkgpattern */
prop_object_release(tmpd); prop_object_release(tmpd);
xbps_dbg_printf("failed to match " xbps_dbg_printf(xhp, "failed to match "
"pattern %s with %s\n", reqpkg, pkgver_q); "pattern %s with %s\n", reqpkg, pkgver_q);
break; break;
} }
@ -304,9 +309,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Pass 2: check if required dependency has been already * Pass 2: check if required dependency has been already
* added in the transaction dictionary. * added in the transaction dictionary.
*/ */
unsorted = prop_dictionary_get(transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) && if (((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(unsorted, reqpkg)) == NULL) && ((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(unsorted, reqpkg)) == NULL)) { ((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(unsorted, reqpkg)) == NULL)) {
/* error matching required pkgdep */ /* error matching required pkgdep */
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
@ -316,7 +321,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else { } else {
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q); "pkgver", &pkgver_q);
xbps_dbg_printf_append(" (%s queued " xbps_dbg_printf_append(xhp, " (%s queued "
"in transaction).\n", pkgver_q); "in transaction).\n", pkgver_q);
continue; continue;
} }
@ -325,35 +330,37 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* If dependency does not match add pkg into the missing * If dependency does not match add pkg into the missing
* deps array and pass to next one. * deps array and pass to next one.
*/ */
if (((curpkgd = xbps_rpool_find_virtualpkg_conf(reqpkg, true)) == NULL) && if (((curpkgd = xbps_rpool_find_virtualpkg_conf(xhp, reqpkg, true)) == NULL) &&
((curpkgd = xbps_rpool_find_pkg(reqpkg, true, true)) == NULL) && ((curpkgd = xbps_rpool_find_pkg(xhp, reqpkg, true, true)) == NULL) &&
((curpkgd = xbps_rpool_find_virtualpkg(reqpkg, true)) == NULL)) { ((curpkgd = xbps_rpool_find_virtualpkg(xhp, reqpkg, true)) == NULL)) {
/* pkg not found, there was some error */ /* pkg not found, there was some error */
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
xbps_dbg_printf("failed to find pkg " xbps_dbg_printf(xhp, "failed to find pkg "
"for `%s' in rpool: %s\n", "for `%s' in rpool: %s\n",
reqpkg, strerror(errno)); reqpkg, strerror(errno));
rv = errno; rv = errno;
break; break;
} }
rv = add_missing_reqdep(trans_mdeps, reqpkg); rv = add_missing_reqdep(xhp, reqpkg);
if (rv != 0 && rv != EEXIST) { if (rv != 0 && rv != EEXIST) {
xbps_dbg_printf_append("`%s': " xbps_dbg_printf_append(xhp, "`%s': "
"add_missing_reqdep failed %s\n", "add_missing_reqdep failed %s\n",
reqpkg); reqpkg);
break; break;
} else if (rv == EEXIST) { } else if (rv == EEXIST) {
xbps_dbg_printf_append("`%s' missing " xbps_dbg_printf_append(xhp, "`%s' missing "
"dep already added.\n", reqpkg); "dep already added.\n", reqpkg);
rv = 0; rv = 0;
continue; continue;
} else { } else {
xbps_dbg_printf_append("`%s' added " xbps_dbg_printf_append(xhp, "`%s' added "
"into the missing deps array.\n", "into the missing deps array.\n",
reqpkg); reqpkg);
continue; continue;
} }
} }
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
/* /*
* Check if package has matched conflicts. * Check if package has matched conflicts.
*/ */
@ -362,9 +369,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is on repo, add it into the transaction dictionary. * Package is on repo, add it into the transaction dictionary.
*/ */
prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
rv = store_dependency(unsorted, curpkgd, state, depth); rv = store_dependency(xhp, curpkgd, state, depth);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("store_dependency failed for " xbps_dbg_printf(xhp, "store_dependency failed for "
"`%s': %s\n", reqpkg, strerror(rv)); "`%s': %s\n", reqpkg, strerror(rv));
prop_object_release(curpkgd); prop_object_release(curpkgd);
break; break;
@ -379,21 +386,20 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} }
prop_object_release(curpkgd); prop_object_release(curpkgd);
if (xhp->flags & XBPS_FLAG_DEBUG) { if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf(""); xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++) for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" "); xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append(" %s: finding dependencies:\n", xbps_dbg_printf_append(xhp,
pkgver_q); "%s: finding dependencies:\n", pkgver_q);
} }
/* /*
* Recursively find rundeps for current pkg dictionary. * Recursively find rundeps for current pkg dictionary.
*/ */
(*depth)++; (*depth)++;
rv = find_repo_deps(transd, trans_mdeps, curpkgrdeps, rv = find_repo_deps(xhp, curpkgrdeps, pkgver_q, depth);
pkgver_q, depth);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n", xbps_dbg_printf(xhp, "Error checking %s for rundeps: %s\n",
reqpkg, strerror(rv)); reqpkg, strerror(rv));
break; break;
} }
@ -407,7 +413,7 @@ int HIDDEN
xbps_repository_find_pkg_deps(struct xbps_handle *xhp, xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd) prop_dictionary_t repo_pkgd)
{ {
prop_array_t mdeps, pkg_rdeps; prop_array_t pkg_rdeps;
const char *pkgver; const char *pkgver;
size_t depth = 0; size_t depth = 0;
@ -416,11 +422,10 @@ xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
return 0; return 0;
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver); xbps_dbg_printf(xhp, "Finding required dependencies for '%s':\n", pkgver);
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
/* /*
* This will find direct and indirect deps, if any of them is not * This will find direct and indirect deps, if any of them is not
* there it will be added into the missing_deps array. * there it will be added into the missing_deps array.
*/ */
return find_repo_deps(xhp->transd, mdeps, pkg_rdeps, pkgver, &depth); return find_repo_deps(xhp, pkg_rdeps, pkgver, &depth);
} }

View File

@ -64,7 +64,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
/* /*
* If index file is not there, skip. * If index file is not there, skip.
*/ */
plist = xbps_pkg_index_plist(repouri); plist = xbps_pkg_index_plist(xhp, repouri);
if (plist == NULL) { if (plist == NULL) {
rv = errno; rv = errno;
goto out; goto out;
@ -72,7 +72,8 @@ xbps_rpool_init(struct xbps_handle *xhp)
array = prop_array_internalize_from_zfile(plist); array = prop_array_internalize_from_zfile(plist);
free(plist); free(plist);
if (array == NULL) { if (array == NULL) {
xbps_dbg_printf("[rpool] `%s' cannot be internalized:" xbps_dbg_printf(xhp,
"[rpool] `%s' cannot be internalized:"
" %s\n", repouri, strerror(errno)); " %s\n", repouri, strerror(errno));
nmissing++; nmissing++;
continue; continue;
@ -102,7 +103,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
prop_object_release(d); prop_object_release(d);
goto out; goto out;
} }
xbps_dbg_printf("[rpool] `%s' registered.\n", repouri); xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri);
} }
if (ntotal - nmissing == 0) { if (ntotal - nmissing == 0) {
/* no repositories available, error out */ /* no repositories available, error out */
@ -111,7 +112,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
} }
prop_array_make_immutable(xhp->repo_pool); prop_array_make_immutable(xhp->repo_pool);
xbps_dbg_printf("[rpool] initialized ok.\n"); xbps_dbg_printf(xhp, "[rpool] initialized ok.\n");
out: out:
if (rv != 0) if (rv != 0)
xbps_rpool_release(xhp); xbps_rpool_release(xhp);
@ -135,18 +136,18 @@ xbps_rpool_release(struct xbps_handle *xhp)
d = prop_array_get(xhp->repo_pool, i); d = prop_array_get(xhp->repo_pool, i);
idx = prop_dictionary_get(d, "index"); idx = prop_dictionary_get(d, "index");
prop_dictionary_get_cstring_nocopy(d, "uri", &uri); prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf("[rpool] unregistered repository '%s'\n", uri); xbps_dbg_printf(xhp, "[rpool] unregistered repository '%s'\n",
uri);
prop_object_release(idx); prop_object_release(idx);
prop_object_release(d); prop_object_release(d);
} }
xhp->repo_pool = NULL; xhp->repo_pool = NULL;
xbps_dbg_printf("[rpool] released ok.\n"); xbps_dbg_printf(xhp, "[rpool] released ok.\n");
} }
int int
xbps_rpool_sync(const char *uri) xbps_rpool_sync(struct xbps_handle *xhp, const char *uri)
{ {
const struct xbps_handle *xhp = xbps_handle_get();
const char *repouri; const char *repouri;
size_t i; size_t i;
@ -161,8 +162,9 @@ xbps_rpool_sync(const char *uri)
/* /*
* Fetch repository index. * Fetch repository index.
*/ */
if (xbps_repository_sync_pkg_index(repouri, XBPS_PKGINDEX) == -1) { if (xbps_repository_sync_pkg_index(xhp, repouri, XBPS_PKGINDEX) == -1) {
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n", xbps_dbg_printf(xhp,
"[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ? strerror(errno) : repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string()); xbps_fetch_error_string());
continue; continue;
@ -170,9 +172,10 @@ xbps_rpool_sync(const char *uri)
/* /*
* Fetch repository files index. * Fetch repository files index.
*/ */
if (xbps_repository_sync_pkg_index(repouri, if (xbps_repository_sync_pkg_index(xhp, repouri,
XBPS_PKGINDEX_FILES) == -1) { XBPS_PKGINDEX_FILES) == -1) {
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n", xbps_dbg_printf(xhp,
"[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ? strerror(errno) : repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string()); xbps_fetch_error_string());
continue; continue;
@ -182,10 +185,11 @@ xbps_rpool_sync(const char *uri)
} }
int int
xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *arg) xbps_rpool_foreach(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, struct xbps_rpool_index *, void *, bool *),
void *arg)
{ {
prop_dictionary_t d; prop_dictionary_t d;
struct xbps_handle *xhp = xbps_handle_get();
struct xbps_rpool_index rpi; struct xbps_rpool_index rpi;
size_t i; size_t i;
int rv = 0; int rv = 0;
@ -195,9 +199,11 @@ xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *a
/* Initialize repository pool */ /* Initialize repository pool */
if ((rv = xbps_rpool_init(xhp)) != 0) { if ((rv = xbps_rpool_init(xhp)) != 0) {
if (rv == ENOTSUP) { if (rv == ENOTSUP) {
xbps_dbg_printf("[rpool] empty repository list.\n"); xbps_dbg_printf(xhp,
"[rpool] empty repository list.\n");
} else if (rv != ENOENT && rv != ENOTSUP) { } else if (rv != ENOENT && rv != ENOTSUP) {
xbps_dbg_printf("[rpool] couldn't initialize: %s\n", xbps_dbg_printf(xhp,
"[rpool] couldn't initialize: %s\n",
strerror(rv)); strerror(rv));
} }
return rv; return rv;
@ -207,7 +213,7 @@ xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *a
d = prop_array_get(xhp->repo_pool, i); d = prop_array_get(xhp->repo_pool, i);
prop_dictionary_get_cstring_nocopy(d, "uri", &rpi.uri); prop_dictionary_get_cstring_nocopy(d, "uri", &rpi.uri);
rpi.repo = prop_dictionary_get(d, "index"); rpi.repo = prop_dictionary_get(d, "index");
rv = (*fn)(&rpi, arg, &done); rv = (*fn)(xhp, &rpi, arg, &done);
if (rv != 0 || done) if (rv != 0 || done)
break; break;
} }

View File

@ -45,10 +45,15 @@ struct repo_pool_fpkg {
}; };
static int static int
repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) repo_find_virtualpkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{ {
struct repo_pool_fpkg *rpf = arg; struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->bypattern) { if (rpf->bypattern) {
rpf->pkgd = rpf->pkgd =
xbps_find_virtualpkg_in_array_by_pattern(rpi->repo, xbps_find_virtualpkg_in_array_by_pattern(rpi->repo,
@ -68,18 +73,21 @@ repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
} }
static int static int
repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) repo_find_virtualpkg_conf_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{ {
struct repo_pool_fpkg *rpf = arg; struct repo_pool_fpkg *rpf = arg;
if (rpf->bypattern) { if (rpf->bypattern) {
rpf->pkgd = rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_pattern(rpi->repo, xbps_find_virtualpkg_conf_in_array_by_pattern(xhp,
rpf->pattern); rpi->repo, rpf->pattern);
} else { } else {
rpf->pkgd = rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_name(rpi->repo, xbps_find_virtualpkg_conf_in_array_by_name(xhp,
rpf->pattern); rpi->repo, rpf->pattern);
} }
if (rpf->pkgd) { if (rpf->pkgd) {
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@ -91,10 +99,15 @@ repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done
} }
static int static int
repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) repo_find_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{ {
struct repo_pool_fpkg *rpf = arg; struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->exact) { if (rpf->exact) {
/* exact match by pkgver */ /* exact match by pkgver */
rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo, rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo,
@ -122,13 +135,17 @@ repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
} }
static int static int
repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) repo_find_best_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{ {
struct repo_pool_fpkg *rpf = arg; struct repo_pool_fpkg *rpf = arg;
const char *repopkgver; const char *repopkgver;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
(void)done; (void)done;
(void)xhp;
if (rpf->bypattern) { if (rpf->bypattern) {
pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo, pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo,
@ -141,14 +158,16 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
if (errno && errno != ENOENT) if (errno && errno != ENOENT)
return errno; return errno;
xbps_dbg_printf("[rpool] Package '%s' not found in repository " xbps_dbg_printf(xhp,
"[rpool] Package '%s' not found in repository "
"'%s'.\n", rpf->pattern, rpi->uri); "'%s'.\n", rpf->pattern, rpi->uri);
return 0; return 0;
} }
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &repopkgver); "pkgver", &repopkgver);
if (rpf->bestpkgver == NULL) { if (rpf->bestpkgver == NULL) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n", xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri); repopkgver, rpi->uri);
rpf->pkgd = pkgd; rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@ -160,7 +179,8 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
* version from current package in repository. * version from current package in repository.
*/ */
if (xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) { if (xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n", xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri); repopkgver, rpi->uri);
rpf->pkgd = pkgd; rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@ -178,7 +198,10 @@ typedef enum {
} pkg_repo_type_t; } pkg_repo_type_t;
static prop_dictionary_t static prop_dictionary_t
repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type) repo_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
pkg_repo_type_t type)
{ {
struct repo_pool_fpkg rpf; struct repo_pool_fpkg rpf;
int rv = 0; int rv = 0;
@ -195,31 +218,31 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
* Find exact pkg version. * Find exact pkg version.
*/ */
rpf.exact = true; rpf.exact = true;
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf); rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break; break;
case BEST_PKG: case BEST_PKG:
/* /*
* Find best pkg version. * Find best pkg version.
*/ */
rv = xbps_rpool_foreach(repo_find_best_pkg_cb, &rpf); rv = xbps_rpool_foreach(xhp, repo_find_best_pkg_cb, &rpf);
break; break;
case VIRTUAL_PKG: case VIRTUAL_PKG:
/* /*
* Find virtual pkg. * Find virtual pkg.
*/ */
rv = xbps_rpool_foreach(repo_find_virtualpkg_cb, &rpf); rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_cb, &rpf);
break; break;
case VIRTUAL_CONF_PKG: case VIRTUAL_CONF_PKG:
/* /*
* Find virtual pkg as specified in configuration file. * Find virtual pkg as specified in configuration file.
*/ */
rv = xbps_rpool_foreach(repo_find_virtualpkg_conf_cb, &rpf); rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_conf_cb, &rpf);
break; break;
case REAL_PKG: case REAL_PKG:
/* /*
* Find real pkg. * Find real pkg.
*/ */
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf); rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break; break;
} }
if (rv != 0) { if (rv != 0) {
@ -231,42 +254,51 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
} }
prop_dictionary_t prop_dictionary_t
xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern) xbps_rpool_find_virtualpkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{ {
assert(pkg != NULL); assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_PKG); return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_PKG);
} }
prop_dictionary_t prop_dictionary_t
xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypattern) xbps_rpool_find_virtualpkg_conf(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{ {
assert(pkg != NULL); assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_CONF_PKG); return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_CONF_PKG);
} }
prop_dictionary_t prop_dictionary_t
xbps_rpool_find_pkg(const char *pkg, bool bypattern, bool best) xbps_rpool_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best)
{ {
assert(pkg != NULL); assert(pkg != NULL);
if (best) if (best)
return repo_find_pkg(pkg, bypattern, BEST_PKG); return repo_find_pkg(xhp, pkg, bypattern, BEST_PKG);
return repo_find_pkg(pkg, bypattern, REAL_PKG); return repo_find_pkg(xhp, pkg, bypattern, REAL_PKG);
} }
prop_dictionary_t prop_dictionary_t
xbps_rpool_find_pkg_exact(const char *pkgver) xbps_rpool_find_pkg_exact(struct xbps_handle *xhp, const char *pkgver)
{ {
assert(pkgver != NULL); assert(pkgver != NULL);
return repo_find_pkg(pkgver, false, EXACT_PKG); return repo_find_pkg(xhp, pkgver, false, EXACT_PKG);
} }
prop_dictionary_t prop_dictionary_t
xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf) xbps_rpool_dictionary_metadata_plist(struct xbps_handle *xhp,
const char *pattern,
const char *plistf)
{ {
prop_dictionary_t pkgd = NULL, plistd = NULL; prop_dictionary_t pkgd = NULL, plistd = NULL;
const char *repoloc; const char *repoloc;
@ -284,15 +316,15 @@ xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf)
* libfetch! * libfetch!
*/ */
if (xbps_pkgpattern_version(pattern)) if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(pattern, true, false); pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else else
pkgd = xbps_rpool_find_pkg(pattern, false, true); pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
if (pkgd == NULL) if (pkgd == NULL)
goto out; goto out;
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
url = xbps_path_from_repository_uri(pkgd, repoloc); url = xbps_path_from_repository_uri(xhp, pkgd, repoloc);
if (url == NULL) { if (url == NULL) {
errno = EINVAL; errno = EINVAL;
goto out; goto out;

View File

@ -86,10 +86,11 @@ xbps_get_remote_repo_string(const char *uri)
* size and/or mtime match) and 1 if downloaded successfully. * size and/or mtime match) and 1 if downloaded successfully.
*/ */
int int
xbps_repository_sync_pkg_index(const char *uri, const char *plistf) xbps_repository_sync_pkg_index(struct xbps_handle *xhp,
const char *uri,
const char *plistf)
{ {
prop_array_t array; prop_array_t array;
struct xbps_handle *xhp;
struct url *url = NULL; struct url *url = NULL;
struct stat st; struct stat st;
const char *fetch_outputdir, *fetchstr = NULL; const char *fetch_outputdir, *fetchstr = NULL;
@ -100,7 +101,6 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
assert(uri != NULL); assert(uri != NULL);
tmp_metafile = rpidx = lrepodir = lrepofile = NULL; tmp_metafile = rpidx = lrepodir = lrepofile = NULL;
xhp = xbps_handle_get();
/* ignore non remote repositories */ /* ignore non remote repositories */
if (!xbps_check_is_repository_uri_remote(uri)) if (!xbps_check_is_repository_uri_remote(uri))
@ -118,7 +118,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Create metadir if necessary. * Create metadir if necessary.
*/ */
if ((rv = xbps_mkpath(xhp->metadir, 0755)) == -1) { if ((rv = xbps_mkpath(xhp->metadir, 0755)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL,
errno, NULL, NULL, errno, NULL, NULL,
"[reposync] failed to create metadir `%s': %s", "[reposync] failed to create metadir `%s': %s",
xhp->metadir, strerror(errno)); xhp->metadir, strerror(errno));
@ -162,15 +162,15 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
fetch_outputdir = xhp->metadir; fetch_outputdir = xhp->metadir;
/* reposync start cb */ /* reposync start cb */
xbps_set_cb_state(XBPS_STATE_REPOSYNC, 0, NULL, NULL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC, 0, NULL, NULL,
"Synchronizing %s for `%s'...", plistf, uri); "Synchronizing %s for `%s'...", plistf, uri);
/* /*
* Download plist index file from repository. * Download plist index file from repository.
*/ */
if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) { if (xbps_fetch_file(xhp, rpidx, fetch_outputdir, true, NULL) == -1) {
/* reposync error cb */ /* reposync error cb */
fetchstr = xbps_fetch_error_string(); fetchstr = xbps_fetch_error_string();
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL,
fetchLastErrCode != 0 ? fetchLastErrCode : errno, fetchLastErrCode != 0 ? fetchLastErrCode : errno,
NULL, NULL, NULL, NULL,
"[reposync] failed to fetch file `%s': %s", "[reposync] failed to fetch file `%s': %s",
@ -183,11 +183,11 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
/* /*
* Make sure that downloaded plist file can be internalized, i.e * Make sure that downloaded plist file can be internalized, i.e
* some HTTP servers don't return proper errors and sometimes * some HTTP servers don't return proper errors and sometimes
* you get an HTML ASCII file :-) you get an HTML ASCII file :-)
*/ */
array = prop_array_internalize_from_zfile(tmp_metafile); array = prop_array_internalize_from_zfile(tmp_metafile);
if (array == NULL) { if (array == NULL) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, 0, NULL, NULL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, 0, NULL, NULL,
"[reposync] downloaded file `%s' is not valid.", rpidx); "[reposync] downloaded file `%s' is not valid.", rpidx);
(void)unlink(tmp_metafile); (void)unlink(tmp_metafile);
rv = -1; rv = -1;
@ -204,7 +204,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Create local repodir to store plist index file. * Create local repodir to store plist index file.
*/ */
if ((rv = xbps_mkpath(lrepodir, 0755)) == -1) { if ((rv = xbps_mkpath(lrepodir, 0755)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
"[reposync] failed to create repodir for `%s': %s", "[reposync] failed to create repodir for `%s': %s",
lrepodir, strerror(rv)); lrepodir, strerror(rv));
goto out; goto out;
@ -214,7 +214,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Rename to destination file now it has been fetched successfully. * Rename to destination file now it has been fetched successfully.
*/ */
if ((rv = rename(tmp_metafile, lrepofile)) == -1) { if ((rv = rename(tmp_metafile, lrepofile)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL, xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
"[reposync] failed to rename index file `%s' to `%s': %s", "[reposync] failed to rename index file `%s' to `%s': %s",
tmp_metafile, lrepofile, strerror(errno)); tmp_metafile, lrepofile, strerror(errno));
} else { } else {

View File

@ -57,7 +57,7 @@
*/ */
static int static int
check_binpkgs_hash(prop_object_iterator_t iter) check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
{ {
prop_object_t obj; prop_object_t obj;
const char *pkgver, *repoloc, *filen, *sha256, *trans; const char *pkgver, *repoloc, *filen, *sha256, *trans;
@ -83,17 +83,17 @@ check_binpkgs_hash(prop_object_iterator_t iter)
"filename-sha256", &sha256); "filename-sha256", &sha256);
assert(sha256 != NULL); assert(sha256 != NULL);
binfile = xbps_path_from_repository_uri(obj, repoloc); binfile = xbps_path_from_repository_uri(xhp, obj, repoloc);
if (binfile == NULL) { if (binfile == NULL) {
rv = EINVAL; rv = EINVAL;
break; break;
} }
xbps_set_cb_state(XBPS_STATE_VERIFY, 0, pkgname, version, xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgname, version,
"Verifying `%s' package integrity...", filen, repoloc); "Verifying `%s' package integrity...", filen, repoloc);
rv = xbps_file_hash_check(binfile, sha256); rv = xbps_file_hash_check(binfile, sha256);
if (rv != 0) { if (rv != 0) {
free(binfile); free(binfile);
xbps_set_cb_state(XBPS_STATE_VERIFY_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_VERIFY_FAIL,
rv, pkgname, version, rv, pkgname, version,
"Failed to verify `%s' package integrity: %s", "Failed to verify `%s' package integrity: %s",
filen, strerror(rv)); filen, strerror(rv));
@ -130,7 +130,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen); prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
assert(filen != NULL); assert(filen != NULL);
binfile = xbps_path_from_repository_uri(obj, repoloc); binfile = xbps_path_from_repository_uri(xhp, obj, repoloc);
if (binfile == NULL) { if (binfile == NULL) {
rv = EINVAL; rv = EINVAL;
break; break;
@ -146,7 +146,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
* Create cachedir. * Create cachedir.
*/ */
if (xbps_mkpath(xhp->cachedir, 0755) == -1) { if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [trans] cannot create cachedir `%s': %s", "%s: [trans] cannot create cachedir `%s': %s",
pkgver, xhp->cachedir, strerror(errno)); pkgver, xhp->cachedir, strerror(errno));
@ -154,17 +154,17 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
rv = errno; rv = errno;
break; break;
} }
xbps_set_cb_state(XBPS_STATE_DOWNLOAD, xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
0, pkgname, version, 0, pkgname, version,
"Downloading binary package `%s' (from `%s')...", "Downloading binary package `%s' (from `%s')...",
filen, repoloc); filen, repoloc);
/* /*
* Fetch binary package. * Fetch binary package.
*/ */
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL); rv = xbps_fetch_file(xhp, binfile, xhp->cachedir, false, NULL);
if (rv == -1) { if (rv == -1) {
fetchstr = xbps_fetch_error_string(); fetchstr = xbps_fetch_error_string();
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
fetchLastErrCode != 0 ? fetchLastErrCode : errno, fetchLastErrCode != 0 ? fetchLastErrCode : errno,
pkgname, version, pkgname, version,
"%s: [trans] failed to download binary package " "%s: [trans] failed to download binary package "
@ -182,9 +182,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
} }
int int
xbps_transaction_commit(void) xbps_transaction_commit(struct xbps_handle *xhp)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
size_t i; size_t i;
@ -201,26 +200,26 @@ xbps_transaction_commit(void)
/* /*
* Download binary packages (if they come from a remote repository). * Download binary packages (if they come from a remote repository).
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL); xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
if ((rv = download_binpkgs(xhp, iter)) != 0) if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out; goto out;
/* /*
* Check SHA256 hashes for binary packages in transaction. * Check SHA256 hashes for binary packages in transaction.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL); xbps_set_cb_state(xhp, XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
if ((rv = check_binpkgs_hash(iter)) != 0) if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
goto out; goto out;
/* /*
* Install, update, configure or remove packages as specified * Install, update, configure or remove packages as specified
* in the transaction dictionary. * in the transaction dictionary.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL); xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
i = 0; i = 0;
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if ((xhp->transaction_frequency_flush > 0) && if ((xhp->transaction_frequency_flush > 0) &&
(++i >= xhp->transaction_frequency_flush)) { (++i >= xhp->transaction_frequency_flush)) {
rv = xbps_pkgdb_update(true); rv = xbps_pkgdb_update(xhp, true);
if (rv != 0 && rv != ENOENT) if (rv != 0 && rv != ENOENT)
goto out; goto out;
@ -241,14 +240,14 @@ xbps_transaction_commit(void)
prop_dictionary_get_bool(obj, "remove-and-update", prop_dictionary_get_bool(obj, "remove-and-update",
&update); &update);
prop_dictionary_get_bool(obj, "softreplace", &sr); prop_dictionary_get_bool(obj, "softreplace", &sr);
rv = xbps_remove_pkg(pkgname, version, update, sr); rv = xbps_remove_pkg(xhp, pkgname, version, update, sr);
if (rv != 0) if (rv != 0)
goto out; goto out;
} else if (strcmp(tract, "configure") == 0) { } else if (strcmp(tract, "configure") == 0) {
/* /*
* Reconfigure pending package. * Reconfigure pending package.
*/ */
rv = xbps_configure_pkg(pkgname, false, false, false); rv = xbps_configure_pkg(xhp, pkgname, false, false, false);
if (rv != 0) if (rv != 0)
goto out; goto out;
} else { } else {
@ -265,12 +264,12 @@ xbps_transaction_commit(void)
* Update a package: execute pre-remove * Update a package: execute pre-remove
* action if found before unpacking. * action if found before unpacking.
*/ */
xbps_set_cb_state(XBPS_STATE_UPDATE, 0, xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0,
pkgname, version, NULL); pkgname, version, NULL);
rv = xbps_remove_pkg(pkgname, version, rv = xbps_remove_pkg(xhp, pkgname, version,
true, false); true, false);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state( xbps_set_cb_state(xhp,
XBPS_STATE_UPDATE_FAIL, XBPS_STATE_UPDATE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [trans] failed to update " "%s: [trans] failed to update "
@ -280,25 +279,25 @@ xbps_transaction_commit(void)
} }
} else { } else {
/* Install a package */ /* Install a package */
xbps_set_cb_state(XBPS_STATE_INSTALL, 0, xbps_set_cb_state(xhp, XBPS_STATE_INSTALL,
pkgname, version, NULL); 0, pkgname, version, NULL);
} }
/* /*
* Unpack binary package. * Unpack binary package.
*/ */
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0)
goto out; goto out;
/* /*
* Register package. * Register package.
*/ */
if ((rv = xbps_register_pkg(obj, false)) != 0) if ((rv = xbps_register_pkg(xhp, obj, false)) != 0)
goto out; goto out;
} }
} }
prop_object_iterator_reset(iter); prop_object_iterator_reset(iter);
/* force a flush now packages were removed/unpacked */ /* force a flush now packages were removed/unpacked */
if ((rv = xbps_pkgdb_update(true)) != 0) if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out; goto out;
/* if there are no packages to install or update we are done */ /* if there are no packages to install or update we are done */
@ -307,13 +306,13 @@ xbps_transaction_commit(void)
/* /*
* Configure all unpacked packages. * Configure all unpacked packages.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL); xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
i = 0; i = 0;
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (xhp->transaction_frequency_flush > 0 && if (xhp->transaction_frequency_flush > 0 &&
++i >= xhp->transaction_frequency_flush) { ++i >= xhp->transaction_frequency_flush) {
if ((rv = xbps_pkgdb_update(true)) != 0) if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out; goto out;
i = 0; i = 0;
@ -330,7 +329,7 @@ xbps_transaction_commit(void)
if (strcmp(tract, "update") == 0) if (strcmp(tract, "update") == 0)
update = true; update = true;
rv = xbps_configure_pkg(pkgname, false, update, false); rv = xbps_configure_pkg(xhp, pkgname, false, update, false);
if (rv != 0) if (rv != 0)
goto out; goto out;
/* /*
@ -338,16 +337,16 @@ xbps_transaction_commit(void)
* installed or updated. * installed or updated.
*/ */
if (update) { if (update) {
xbps_set_cb_state(XBPS_STATE_UPDATE_DONE, 0, xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
pkgname, version, NULL); pkgname, version, NULL);
} else { } else {
xbps_set_cb_state(XBPS_STATE_INSTALL_DONE, 0, xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
pkgname, version, NULL); pkgname, version, NULL);
} }
} }
/* Force a flush now that packages are configured */ /* Force a flush now that packages are configured */
rv = xbps_pkgdb_update(true); rv = xbps_pkgdb_update(xhp, true);
out: out:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);

View File

@ -53,7 +53,7 @@
*/ */
static int static int
compute_transaction_stats(prop_dictionary_t transd) compute_transaction_stats(struct xbps_handle *xhp)
{ {
prop_dictionary_t pkg_metad; prop_dictionary_t pkg_metad;
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -66,7 +66,7 @@ compute_transaction_stats(prop_dictionary_t transd)
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0; inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
tsize = dlsize = instsize = rmsize = 0; tsize = dlsize = instsize = rmsize = 0;
iter = xbps_array_iter_from_dict(transd, "packages"); iter = xbps_array_iter_from_dict(xhp->transd, "packages");
if (iter == NULL) if (iter == NULL)
return EINVAL; return EINVAL;
@ -98,8 +98,8 @@ compute_transaction_stats(prop_dictionary_t transd)
if ((strcmp(tract, "remove") == 0) || if ((strcmp(tract, "remove") == 0) ||
(strcmp(tract, "update") == 0)) { (strcmp(tract, "update") == 0)) {
pkg_metad = pkg_metad =
xbps_dictionary_from_metadata_plist(pkgname, xbps_dictionary_from_metadata_plist(xhp,
XBPS_PKGPROPS); pkgname, XBPS_PKGPROPS);
if (pkg_metad == NULL) if (pkg_metad == NULL)
continue; continue;
prop_dictionary_get_uint64(pkg_metad, prop_dictionary_get_uint64(pkg_metad,
@ -121,25 +121,25 @@ compute_transaction_stats(prop_dictionary_t transd)
} }
if (inst_pkgcnt && if (inst_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-install-pkgs", !prop_dictionary_set_uint32(xhp->transd, "total-install-pkgs",
inst_pkgcnt)) { inst_pkgcnt)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (up_pkgcnt && if (up_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-update-pkgs", !prop_dictionary_set_uint32(xhp->transd, "total-update-pkgs",
up_pkgcnt)) { up_pkgcnt)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (cf_pkgcnt && if (cf_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-configure-pkgs", !prop_dictionary_set_uint32(xhp->transd, "total-configure-pkgs",
cf_pkgcnt)) { cf_pkgcnt)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (rm_pkgcnt && if (rm_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-remove-pkgs", !prop_dictionary_set_uint32(xhp->transd, "total-remove-pkgs",
rm_pkgcnt)) { rm_pkgcnt)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -158,7 +158,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total installed * Add object in transaction dictionary with total installed
* size that it will take. * size that it will take.
*/ */
if (!prop_dictionary_set_uint64(transd, if (!prop_dictionary_set_uint64(xhp->transd,
"total-installed-size", instsize)) { "total-installed-size", instsize)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -167,7 +167,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total download * Add object in transaction dictionary with total download
* size that needs to be sucked in. * size that needs to be sucked in.
*/ */
if (!prop_dictionary_set_uint64(transd, if (!prop_dictionary_set_uint64(xhp->transd,
"total-download-size", dlsize)) { "total-download-size", dlsize)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -176,7 +176,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total size to be * Add object in transaction dictionary with total size to be
* freed from packages to be removed. * freed from packages to be removed.
*/ */
if (!prop_dictionary_set_uint64(transd, if (!prop_dictionary_set_uint64(xhp->transd,
"total-removed-size", rmsize)) { "total-removed-size", rmsize)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -233,10 +233,9 @@ xbps_transaction_init(struct xbps_handle *xhp)
} }
int int
xbps_transaction_prepare(void) xbps_transaction_prepare(struct xbps_handle *xhp)
{ {
prop_array_t mdeps, conflicts; prop_array_t mdeps, conflicts;
struct xbps_handle *xhp = xbps_handle_get();
int rv = 0; int rv = 0;
if (xhp->transd == NULL) if (xhp->transd == NULL)
@ -259,7 +258,7 @@ xbps_transaction_prepare(void)
/* /*
* Check for packages to be replaced. * Check for packages to be replaced.
*/ */
if ((rv = xbps_transaction_package_replace(xhp->transd)) != 0) { if ((rv = xbps_transaction_package_replace(xhp)) != 0) {
prop_object_release(xhp->transd); prop_object_release(xhp->transd);
xhp->transd = NULL; xhp->transd = NULL;
return rv; return rv;
@ -277,7 +276,7 @@ xbps_transaction_prepare(void)
* number of packages to be installed, updated, configured * number of packages to be installed, updated, configured
* and removed to the transaction dictionary. * and removed to the transaction dictionary.
*/ */
if ((rv = compute_transaction_stats(xhp->transd)) != 0) { if ((rv = compute_transaction_stats(xhp)) != 0) {
prop_object_release(xhp->transd); prop_object_release(xhp->transd);
xhp->transd = NULL; xhp->transd = NULL;
return rv; return rv;

View File

@ -57,12 +57,15 @@ enum {
}; };
static int static int
transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact, transaction_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best,
bool exact,
int action) int action)
{ {
prop_dictionary_t pkg_pkgdb, pkg_repod; prop_dictionary_t pkg_pkgdb, pkg_repod;
prop_array_t unsorted; prop_array_t unsorted;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *repoloc, *repover, *instver, *reason; const char *pkgname, *repoloc, *repover, *instver, *reason;
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -74,7 +77,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
reason = "install"; reason = "install";
} else { } else {
/* update */ /* update */
if ((pkg_pkgdb = xbps_pkgdb_get_pkgd(pkg, false)) == NULL) if ((pkg_pkgdb = xbps_pkgdb_get_pkgd(xhp, pkg, false)) == NULL)
return ENODEV; return ENODEV;
reason = "update"; reason = "update";
@ -85,22 +88,24 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
*/ */
if (action == TRANS_INSTALL) { if (action == TRANS_INSTALL) {
if (exact) { if (exact) {
if ((pkg_repod = xbps_rpool_find_pkg_exact(pkg)) == NULL) { pkg_repod = xbps_rpool_find_pkg_exact(xhp, pkg);
if (pkg_repod == NULL) {
/* not found */ /* not found */
rv = errno; rv = errno;
goto out; goto out;
} }
} else { } else {
if (((pkg_repod = xbps_rpool_find_pkg(pkg, bypattern, best)) == NULL) && if (((pkg_repod = xbps_rpool_find_pkg(xhp, pkg, bypattern, best)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg_conf(pkg, bypattern)) == NULL) && ((pkg_repod = xbps_rpool_find_virtualpkg_conf(xhp, pkg, bypattern)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg(pkg, bypattern)) == NULL)) { ((pkg_repod = xbps_rpool_find_virtualpkg(xhp, pkg, bypattern)) == NULL)) {
/* not found */ /* not found */
rv = errno; rv = errno;
goto out; goto out;
} }
} }
} else { } else {
if ((pkg_repod = xbps_rpool_find_pkg(pkg, false, true)) == NULL) { pkg_repod = xbps_rpool_find_pkg(xhp, pkg, false, true);
if (pkg_repod == NULL) {
/* not found */ /* not found */
rv = errno; rv = errno;
goto out; goto out;
@ -118,7 +123,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
"version", &instver); "version", &instver);
prop_object_release(pkg_pkgdb); prop_object_release(pkg_pkgdb);
if (xbps_cmpver(repover, instver) <= 0) { if (xbps_cmpver(repover, instver) <= 0) {
xbps_dbg_printf("[rpool] Skipping `%s-%s' " xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
"(installed: %s-%s) from repository `%s'\n", "(installed: %s-%s) from repository `%s'\n",
pkgname, repover, pkgname, instver, repoloc); pkgname, repover, pkgname, instver, repoloc);
rv = EEXIST; rv = EEXIST;
@ -146,7 +151,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
* Set package state in dictionary with same state than the * Set package state in dictionary with same state than the
* package currently uses, otherwise not-installed. * package currently uses, otherwise not-installed.
*/ */
if ((rv = xbps_pkg_state_installed(pkgname, &state)) != 0) { if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
if (rv != ENOENT) if (rv != ENOENT)
goto out; goto out;
/* Package not installed, don't error out */ /* Package not installed, don't error out */
@ -186,7 +191,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
rv = errno; rv = errno;
goto out; goto out;
} }
xbps_dbg_printf("%s-%s: added into the transaction (%s).\n", xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n",
pkgname, repover, repoloc); pkgname, repover, repoloc);
out: out:
@ -197,10 +202,9 @@ out:
} }
int int
xbps_transaction_update_packages(void) xbps_transaction_update_packages(struct xbps_handle *xhp)
{ {
prop_object_t obj; prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *holdpkgname; const char *pkgname, *holdpkgname;
bool newpkg_found = false; bool newpkg_found = false;
int rv = 0; int rv = 0;
@ -215,12 +219,12 @@ xbps_transaction_update_packages(void)
for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) { for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) {
holdpkgname = cfg_getnstr(xhp->cfg, "PackagesOnHold", x); holdpkgname = cfg_getnstr(xhp->cfg, "PackagesOnHold", x);
if (strcmp(pkgname, holdpkgname) == 0) { if (strcmp(pkgname, holdpkgname) == 0) {
xbps_dbg_printf("[rpool] package %s on hold, " xbps_dbg_printf(xhp, "[rpool] package %s on hold, "
"ignoring updates.\n", pkgname); "ignoring updates.\n", pkgname);
continue; continue;
} }
} }
rv = transaction_find_pkg(pkgname, false, true, rv = transaction_find_pkg(xhp, pkgname, false, true,
false, TRANS_UPDATE); false, TRANS_UPDATE);
if (rv == 0) if (rv == 0)
newpkg_found = true; newpkg_found = true;
@ -237,13 +241,16 @@ xbps_transaction_update_packages(void)
} }
int int
xbps_transaction_update_pkg(const char *pkgname) xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkgname)
{ {
return transaction_find_pkg(pkgname, false, true, false, TRANS_UPDATE); return transaction_find_pkg(xhp, pkgname, false,
true, false, TRANS_UPDATE);
} }
int int
xbps_transaction_install_pkg(const char *pkg, bool reinstall) xbps_transaction_install_pkg(struct xbps_handle *xhp,
const char *pkg,
bool reinstall)
{ {
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
pkg_state_t state; pkg_state_t state;
@ -266,10 +273,10 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
} }
if (exact) { if (exact) {
pkgd = xbps_pkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
free(pkgname); free(pkgname);
} else } else
pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern); pkgd = xbps_pkgdb_get_pkgd(xhp, pkg, bypattern);
if (pkgd) { if (pkgd) {
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) { if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
@ -282,24 +289,25 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
return EEXIST; return EEXIST;
} }
} }
rv = transaction_find_pkg(pkg, bypattern, best, exact, TRANS_INSTALL); rv = transaction_find_pkg(xhp, pkg, bypattern, best, exact, TRANS_INSTALL);
return rv; return rv;
} }
int int
xbps_transaction_remove_pkg(const char *pkgname, bool recursive) xbps_transaction_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool recursive)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
prop_array_t orphans, orphans_pkg, unsorted, reqby; prop_array_t orphans, orphans_pkg, unsorted, reqby;
prop_object_t obj; prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver; const char *pkgver;
size_t count; size_t count;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
if ((pkgd = xbps_pkgdb_get_pkgd(pkgname, false)) == NULL) { if ((pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false)) == NULL) {
/* pkg not installed */ /* pkg not installed */
return ENOENT; return ENOENT;
} }
@ -323,7 +331,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
} }
prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname); prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
orphans = xbps_find_pkg_orphans(orphans_pkg); orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
prop_object_release(orphans_pkg); prop_object_release(orphans_pkg);
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) { if (prop_object_type(orphans) != PROP_TYPE_ARRAY) {
rv = EINVAL; rv = EINVAL;
@ -336,7 +344,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_set_cstring_nocopy(obj, "transaction", "remove"); prop_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
prop_array_add(unsorted, obj); prop_array_add(unsorted, obj);
xbps_dbg_printf("%s: added into transaction (remove).\n", pkgver); xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
} }
prop_object_release(orphans); prop_object_release(orphans);
rmpkg: rmpkg:
@ -346,7 +354,7 @@ rmpkg:
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove"); prop_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
prop_array_add(unsorted, pkgd); prop_array_add(unsorted, pkgd);
xbps_dbg_printf("%s: added into transaction (remove).\n", pkgver); xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
reqby = prop_dictionary_get(pkgd, "requiredby"); reqby = prop_dictionary_get(pkgd, "requiredby");
/* /*
* If target pkg is required by any installed pkg, the client must be aware * If target pkg is required by any installed pkg, the client must be aware
@ -363,16 +371,15 @@ out:
} }
int int
xbps_transaction_autoremove_pkgs(void) xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp)
{ {
prop_array_t orphans, unsorted; prop_array_t orphans, unsorted;
prop_object_t obj; prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver; const char *pkgver;
size_t count; size_t count;
int rv = 0; int rv = 0;
orphans = xbps_find_pkg_orphans(NULL); orphans = xbps_find_pkg_orphans(xhp, NULL);
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
return EINVAL; return EINVAL;
@ -397,7 +404,7 @@ xbps_transaction_autoremove_pkgs(void)
prop_dictionary_set_cstring_nocopy(obj, prop_dictionary_set_cstring_nocopy(obj,
"transaction", "remove"); "transaction", "remove");
prop_array_add(unsorted, obj); prop_array_add(unsorted, obj);
xbps_dbg_printf("%s: added into transaction (remove).\n", xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n",
pkgver); pkgver);
} }
out: out:

View File

@ -34,9 +34,8 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
int HIDDEN int HIDDEN
xbps_transaction_package_replace(prop_dictionary_t transd) xbps_transaction_package_replace(struct xbps_handle *xhp)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_array_t replaces, instd_reqby, transd_unsorted; prop_array_t replaces, instd_reqby, transd_unsorted;
prop_dictionary_t instd, pkg_repod, reppkgd, filesd; prop_dictionary_t instd, pkg_repod, reppkgd, filesd;
prop_object_t obj; prop_object_t obj;
@ -46,9 +45,7 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
bool instd_auto, sr; bool instd_auto, sr;
size_t idx; size_t idx;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); transd_unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
transd_unsorted = prop_dictionary_get(transd, "unsorted_deps");
for (idx = 0; idx < prop_array_count(transd_unsorted); idx++) { for (idx = 0; idx < prop_array_count(transd_unsorted); idx++) {
pkg_repod = prop_array_get(transd_unsorted, idx); pkg_repod = prop_array_get(transd_unsorted, idx);
@ -67,14 +64,15 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
* Find the installed package that matches the pattern * Find the installed package that matches the pattern
* to be replaced. * to be replaced.
*/ */
instd = xbps_find_pkg_dict_installed(pattern, true); instd =
xbps_find_pkg_dict_installed(xhp, pattern, true);
if (instd == NULL) { if (instd == NULL) {
/* /*
* No package installed has been matched, * No package installed has been matched,
* try looking for a virtual package. * try looking for a virtual package.
*/ */
instd = xbps_find_virtualpkg_dict_installed( instd = xbps_find_virtualpkg_dict_installed(
pattern, true); xhp, pattern, true);
if (instd == NULL) if (instd == NULL)
continue; continue;
} }
@ -86,14 +84,16 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
"pkgname", &curpkgname); "pkgname", &curpkgname);
prop_dictionary_get_cstring_nocopy(instd, prop_dictionary_get_cstring_nocopy(instd,
"pkgver", &curpkgver); "pkgver", &curpkgver);
xbps_dbg_printf("Package `%s' will be replaced by `%s', " xbps_dbg_printf(xhp,
"Package `%s' will be replaced by `%s', "
"matched with `%s'\n", curpkgver, pkgver, pattern); "matched with `%s'\n", curpkgver, pkgver, pattern);
/* /*
* Check that we are not replacing the same package, * Check that we are not replacing the same package,
* due to virtual packages. * due to virtual packages.
*/ */
if (strcmp(pkgname, curpkgname) == 0) { if (strcmp(pkgname, curpkgname) == 0) {
xbps_dbg_printf("replaced and new package " xbps_dbg_printf(xhp,
"replaced and new package "
"are equal (%s)\n", pkgname); "are equal (%s)\n", pkgname);
prop_object_release(instd); prop_object_release(instd);
continue; continue;
@ -110,7 +110,8 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
reppkgd = xbps_find_pkg_in_array_by_name( reppkgd = xbps_find_pkg_in_array_by_name(
transd_unsorted, curpkgname, NULL); transd_unsorted, curpkgname, NULL);
if (reppkgd) { if (reppkgd) {
xbps_dbg_printf("found replaced pkg " xbps_dbg_printf(xhp,
"found replaced pkg "
"in transaction\n"); "in transaction\n");
prop_dictionary_set_bool(instd, prop_dictionary_set_bool(instd,
"remove-and-update", true); "remove-and-update", true);

View File

@ -147,44 +147,19 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
static void static void
pkgdep_end(prop_array_t sorted) pkgdep_end(prop_array_t sorted)
{ {
prop_dictionary_t sorted_pkgd;
struct pkgdep *pd; struct pkgdep *pd;
const char *trans;
while ((pd = TAILQ_FIRST(&pkgdep_list)) != NULL) { while ((pd = TAILQ_FIRST(&pkgdep_list)) != NULL) {
TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries); TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries);
if (sorted != NULL && pd->d != NULL) { if (sorted != NULL && pd->d != NULL)
/*
* Do not add duplicate pkg dictionaries with the
* same transaction reason into the sorted array.
*/
sorted_pkgd =
xbps_find_pkg_in_array_by_name(sorted, pd->name, NULL);
if (sorted_pkgd == NULL) {
/* find virtualpkg if no match */
sorted_pkgd =
xbps_find_virtualpkg_in_array_by_name(
sorted, pd->name);
}
if (sorted_pkgd == NULL) {
prop_array_add(sorted, pd->d); prop_array_add(sorted, pd->d);
pkgdep_release(pd);
continue;
}
prop_dictionary_get_cstring_nocopy(sorted_pkgd,
"transaction", &trans);
if (strcmp(trans, pd->trans) == 0) {
pkgdep_release(pd);
continue;
}
prop_array_add(sorted, pd->d);
}
pkgdep_release(pd); pkgdep_release(pd);
} }
} }
static int static int
sort_pkg_rundeps(prop_dictionary_t transd, sort_pkg_rundeps(struct xbps_handle *xhp,
struct pkgdep *pd, struct pkgdep *pd,
prop_array_t pkg_rundeps) prop_array_t pkg_rundeps)
{ {
@ -196,7 +171,7 @@ sort_pkg_rundeps(prop_dictionary_t transd,
size_t i, idx = 0; size_t i, idx = 0;
int rv = 0; int rv = 0;
xbps_dbg_printf_append("\n"); xbps_dbg_printf_append(xhp, "\n");
curpkgidx = pkgdep_find_idx(pd->name, pd->trans); curpkgidx = pkgdep_find_idx(pd->name, pd->trans);
again: again:
@ -207,17 +182,17 @@ again:
rv = ENOMEM; rv = ENOMEM;
break; break;
} }
xbps_dbg_printf(" Required dependency '%s': ", str); xbps_dbg_printf(xhp, " Required dependency '%s': ", str);
pdn = pkgdep_find(pkgnamedep, NULL); pdn = pkgdep_find(pkgnamedep, NULL);
if ((pdn == NULL) && if ((pdn == NULL) &&
xbps_check_is_installed_pkg_by_pattern(str)) { xbps_check_is_installed_pkg_by_name(xhp, pkgnamedep)) {
/* /*
* Package dependency is installed, just add to * Package dependency is installed, just add to
* the list but just mark it as "installed", to avoid * the list but just mark it as "installed", to avoid
* calling xbps_check_is_installed_pkg_by_name(), * calling xbps_check_is_installed_pkg_by_name(),
* which is expensive. * which is expensive.
*/ */
xbps_dbg_printf_append("installed.\n"); xbps_dbg_printf_append(xhp, "installed.\n");
lpd = pkgdep_alloc(NULL, pkgnamedep, "installed"); lpd = pkgdep_alloc(NULL, pkgnamedep, "installed");
if (lpd == NULL) { if (lpd == NULL) {
rv = ENOMEM; rv = ENOMEM;
@ -231,17 +206,17 @@ again:
* Package was added previously into the list * Package was added previously into the list
* and is installed, skip. * and is installed, skip.
*/ */
xbps_dbg_printf_append("installed.\n"); xbps_dbg_printf_append(xhp, "installed.\n");
free(pkgnamedep); free(pkgnamedep);
continue; continue;
} }
/* Find pkg by name */ /* Find pkg by name */
curpkgd = xbps_find_pkg_in_dict_by_name(transd, curpkgd = xbps_find_pkg_in_dict_by_name(xhp->transd,
"unsorted_deps", pkgnamedep); "unsorted_deps", pkgnamedep);
if (curpkgd == NULL) { if (curpkgd == NULL) {
/* find virtualpkg by name if no match */ /* find virtualpkg by name if no match */
curpkgd = curpkgd =
xbps_find_virtualpkg_in_dict_by_name(transd, xbps_find_virtualpkg_in_dict_by_name(xhp->transd,
"unsorted_deps", pkgnamedep); "unsorted_deps", pkgnamedep);
} }
if (curpkgd == NULL) { if (curpkgd == NULL) {
@ -264,7 +239,7 @@ again:
*/ */
TAILQ_INSERT_TAIL(&pkgdep_list, lpd, pkgdep_entries); TAILQ_INSERT_TAIL(&pkgdep_list, lpd, pkgdep_entries);
idx = i; idx = i;
xbps_dbg_printf_append("added into the tail, " xbps_dbg_printf_append(xhp, "added into the tail, "
"checking again...\n"); "checking again...\n");
free(pkgnamedep); free(pkgnamedep);
goto again; goto again;
@ -279,7 +254,7 @@ again:
*/ */
free(pkgnamedep); free(pkgnamedep);
if (pkgdepidx < curpkgidx) { if (pkgdepidx < curpkgidx) {
xbps_dbg_printf_append("already sorted.\n"); xbps_dbg_printf_append(xhp, "already sorted.\n");
pkgdep_release(lpd); pkgdep_release(lpd);
} else { } else {
/* /*
@ -289,7 +264,8 @@ again:
TAILQ_REMOVE(&pkgdep_list, pdn, pkgdep_entries); TAILQ_REMOVE(&pkgdep_list, pdn, pkgdep_entries);
pkgdep_release(pdn); pkgdep_release(pdn);
TAILQ_INSERT_BEFORE(pd, lpd, pkgdep_entries); TAILQ_INSERT_BEFORE(pd, lpd, pkgdep_entries);
xbps_dbg_printf_append("added before `%s'.\n", pd->name); xbps_dbg_printf_append(xhp,
"added before `%s'.\n", pd->name);
} }
} }
@ -301,14 +277,12 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
{ {
prop_array_t sorted, unsorted, rundeps; prop_array_t sorted, unsorted, rundeps;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter;
struct pkgdep *pd; struct pkgdep *pd;
size_t ndeps = 0, cnt = 0; size_t i, ndeps = 0, cnt = 0;
const char *pkgname, *pkgver, *tract; const char *pkgname, *pkgver, *tract;
int rv = 0; int rv = 0;
sorted = prop_array_create(); if ((sorted = prop_array_create()) == NULL)
if (sorted == NULL)
return ENOMEM; return ENOMEM;
/* /*
* Add sorted packages array into transaction dictionary (empty). * Add sorted packages array into transaction dictionary (empty).
@ -330,25 +304,16 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
* all objects in the unsorted array. * all objects in the unsorted array.
*/ */
ndeps = prop_array_count(unsorted); ndeps = prop_array_count(unsorted);
if (!prop_array_ensure_capacity(sorted, ndeps)) {
xbps_dbg_printf("failed to set capacity to the sorted "
"pkgdeps array\n");
return ENOMEM;
}
iter = prop_array_iterator(unsorted);
if (iter == NULL) {
rv = ENOMEM;
goto out;
}
/* /*
* Iterate over the unsorted package dictionaries and sort all * Iterate over the unsorted package dictionaries and sort all
* its package dependencies. * its package dependencies.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { for (i = 0; i < ndeps; i++) {
obj = prop_array_get(unsorted, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
xbps_dbg_printf("Sorting package '%s' (%s): ", pkgver, tract); xbps_dbg_printf(xhp, "Sorting package '%s' (%s): ", pkgver, tract);
pd = pkgdep_find(pkgname, tract); pd = pkgdep_find(pkgname, tract);
if (pd == NULL) { if (pd == NULL) {
@ -358,16 +323,15 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
pd = pkgdep_alloc(obj, pkgname, tract); pd = pkgdep_alloc(obj, pkgname, tract);
if (pd == NULL) { if (pd == NULL) {
pkgdep_end(NULL); pkgdep_end(NULL);
prop_object_iterator_release(iter);
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;
} }
if (strcmp(pd->trans, "remove") == 0) { if (strcmp(pd->trans, "remove") == 0) {
xbps_dbg_printf_append("added into head."); xbps_dbg_printf_append(xhp, "added into head.");
TAILQ_INSERT_HEAD(&pkgdep_list, pd, TAILQ_INSERT_HEAD(&pkgdep_list, pd,
pkgdep_entries); pkgdep_entries);
} else { } else {
xbps_dbg_printf_append("added into tail."); xbps_dbg_printf_append(xhp, "added into tail.");
TAILQ_INSERT_TAIL(&pkgdep_list, pd, TAILQ_INSERT_TAIL(&pkgdep_list, pd,
pkgdep_entries); pkgdep_entries);
} }
@ -378,21 +342,19 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
*/ */
rundeps = prop_dictionary_get(obj, "run_depends"); rundeps = prop_dictionary_get(obj, "run_depends");
if (rundeps == NULL || prop_array_count(rundeps) == 0) { if (rundeps == NULL || prop_array_count(rundeps) == 0) {
xbps_dbg_printf_append("\n"); xbps_dbg_printf_append(xhp, "\n");
cnt++; cnt++;
continue; continue;
} }
/* /*
* Sort package run-time dependencies for this package. * Sort package run-time dependencies for this package.
*/ */
if ((rv = sort_pkg_rundeps(xhp->transd, pd, rundeps)) != 0) { if ((rv = sort_pkg_rundeps(xhp, pd, rundeps)) != 0) {
pkgdep_end(NULL); pkgdep_end(NULL);
prop_object_iterator_release(iter);
goto out; goto out;
} }
cnt++; cnt++;
} }
prop_object_iterator_release(iter);
/* /*
* We are done, now we have to copy all pkg dictionaries * We are done, now we have to copy all pkg dictionaries
* from the sorted list into the "packages" array, and at * from the sorted list into the "packages" array, and at

View File

@ -60,16 +60,17 @@ xbps_check_is_repository_uri_remote(const char *uri)
} }
int int
xbps_check_is_installed_pkg_by_pattern(const char *pattern) xbps_check_is_installed_pkg_by_pattern(struct xbps_handle *xhp,
const char *pattern)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
pkg_state_t state; pkg_state_t state;
assert(pattern != NULL); assert(pattern != NULL);
dict = xbps_find_virtualpkg_dict_installed(pattern, true); dict = xbps_find_virtualpkg_dict_installed(xhp, pattern, true);
if (dict == NULL) { if (dict == NULL) {
dict = xbps_find_pkg_dict_installed(pattern, true); dict = xbps_find_pkg_dict_installed(xhp, pattern, true);
if (dict == NULL) { if (dict == NULL) {
if (errno == ENOENT) { if (errno == ENOENT) {
errno = 0; errno = 0;
@ -96,14 +97,15 @@ xbps_check_is_installed_pkg_by_pattern(const char *pattern)
} }
bool bool
xbps_check_is_installed_pkg_by_name(const char *pkgname) xbps_check_is_installed_pkg_by_name(struct xbps_handle *xhp,
const char *pkgname)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
assert(pkgname != NULL); assert(pkgname != NULL);
if (((pkgd = xbps_find_pkg_dict_installed(pkgname, false)) == NULL) && if (((pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false)) == NULL) &&
((pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false)) == NULL)) ((pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false)) == NULL))
return false; return false;
prop_object_release(pkgd); prop_object_release(pkgd);
@ -190,14 +192,14 @@ xbps_pkgpattern_version(const char *pkg)
} }
static char * static char *
get_pkg_index_remote_plist(const char *uri, const char *plistf) get_pkg_index_remote_plist(struct xbps_handle *xhp,
const char *uri,
const char *plistf)
{ {
struct xbps_handle *xhp;
char *uri_fixed, *repodir; char *uri_fixed, *repodir;
assert(uri != NULL); assert(uri != NULL);
xhp = xbps_handle_get();
uri_fixed = xbps_get_remote_repo_string(uri); uri_fixed = xbps_get_remote_repo_string(uri);
if (uri_fixed == NULL) if (uri_fixed == NULL)
return NULL; return NULL;
@ -208,30 +210,31 @@ get_pkg_index_remote_plist(const char *uri, const char *plistf)
} }
char * char *
xbps_pkg_index_plist(const char *uri) xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri)
{ {
assert(uri != NULL); assert(uri != NULL);
if (xbps_check_is_repository_uri_remote(uri)) if (xbps_check_is_repository_uri_remote(uri))
return get_pkg_index_remote_plist(uri, XBPS_PKGINDEX); return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX);
return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX); return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX);
} }
char * char *
xbps_pkg_index_files_plist(const char *uri) xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri)
{ {
assert(uri != NULL); assert(uri != NULL);
if (xbps_check_is_repository_uri_remote(uri)) if (xbps_check_is_repository_uri_remote(uri))
return get_pkg_index_remote_plist(uri, XBPS_PKGINDEX_FILES); return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX_FILES);
return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX_FILES); return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX_FILES);
} }
char * char *
xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc) xbps_path_from_repository_uri(struct xbps_handle *xhp,
prop_dictionary_t pkg_repod,
const char *repoloc)
{ {
struct xbps_handle *xhp;
const char *filen, *arch; const char *filen, *arch;
char *lbinpkg = NULL; char *lbinpkg = NULL;
@ -242,7 +245,6 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
"filename", &filen)) "filename", &filen))
return NULL; return NULL;
xhp = xbps_handle_get();
/* /*
* First check if binpkg is available in cachedir. * First check if binpkg is available in cachedir.
*/ */

View File

@ -174,11 +174,11 @@ xbps_file_hash_dictionary(prop_dictionary_t d,
} }
int int
xbps_file_hash_check_dictionary(prop_dictionary_t d, xbps_file_hash_check_dictionary(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *file) const char *file)
{ {
struct xbps_handle *xhp = xbps_handle_get();
const char *sha256d = NULL; const char *sha256d = NULL;
char *buf; char *buf;
int rv; int rv;