31#include "xbps_api_impl.h"
34add_missing_reqdep(
struct xbps_handle *xhp,
const char *reqpkg)
37 xbps_object_iterator_t iter = NULL;
40 bool add_pkgdep, pkgfound, update_pkgdep;
43 assert(reqpkg != NULL);
45 add_pkgdep = update_pkgdep = pkgfound =
false;
46 mdeps = xbps_dictionary_get(xhp->
transd,
"missing_deps");
48 iter = xbps_array_iterator(mdeps);
52 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
53 const char *curdep, *curver, *pkgver;
54 char curpkgnamedep[XBPS_NAME_SIZE];
55 char pkgnamedep[XBPS_NAME_SIZE];
57 assert(xbps_object_type(obj) == XBPS_TYPE_STRING);
58 curdep = xbps_string_cstring_nocopy(obj);
61 if (curver == NULL || pkgver == NULL)
69 if (strcmp(pkgnamedep, curpkgnamedep) == 0) {
71 if (strcmp(curver, pkgver) == 0) {
79 xbps_dbg_printf(
"Missing pkgdep name matched, curver: %s newver: %s\n", curver, pkgver);
95 xbps_object_iterator_release(iter);
97 xbps_array_remove(mdeps, idx);
102 xbps_array_add_cstring(mdeps, str);
115 xbps_dictionary_t pkg_repod,
116 unsigned short *depth)
118 xbps_array_t pkg_rdeps = NULL, pkg_provides = NULL;
119 xbps_dictionary_t curpkgd = NULL, repopkgd = NULL;
123 xbps_object_iterator_t iter;
124 const char *curpkg = NULL, *reqpkg = NULL, *pkgver_q = NULL;
125 char pkgname[XBPS_NAME_SIZE], reqpkgname[XBPS_NAME_SIZE];
132 if (*depth >= MAX_DEPTH)
135 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &curpkg);
136 pkg_provides = xbps_dictionary_get(pkg_repod,
"provides");
141 pkg_rdeps = xbps_dictionary_get(pkg_repod,
"run_depends");
142 if (xbps_array_count(pkg_rdeps) == 0)
145 iter = xbps_array_iterator(pkg_rdeps);
148 while ((obj = xbps_object_iterator_next(iter))) {
149 bool error =
false, foundvpkg =
false;
150 bool autoinst =
true;
152 ttype = XBPS_TRANS_UNKNOWN;
153 reqpkg = xbps_string_cstring_nocopy(obj);
155 if (xhp->
flags & XBPS_FLAG_DEBUG) {
157 for (
unsigned short x = 0; x < *depth; x++) {
164 xbps_dbg_printf(
"%s: can't guess pkgname for dependency: %s\n", curpkg, reqpkg);
165 xbps_set_cb_state(xhp, XBPS_STATE_INVALID_DEP, ENXIO, NULL,
166 "%s: can't guess pkgname for dependency '%s'", curpkg, reqpkg);
189 if ((curpkgd = xbps_find_pkg_in_array(queued, reqpkg, 0)) ||
190 (curpkgd = xbps_find_virtualpkg_in_array(xhp, queued, reqpkg, 0))) {
192 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
200 if ((curpkgd = xbps_find_pkg_in_array(pkgs, reqpkg, 0)) ||
201 (curpkgd = xbps_find_virtualpkg_in_array(xhp, pkgs, reqpkg, 0))) {
203 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
204 if (ttype_q != XBPS_TRANS_REMOVE && ttype_q != XBPS_TRANS_HOLD) {
218 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
228 if (curpkgd == NULL) {
229 if (errno && errno != ENOENT) {
232 xbps_dbg_printf(
"failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv));
237 ttype = XBPS_TRANS_INSTALL;
238 state = XBPS_PKG_STATE_NOT_INSTALLED;
244 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
261 char curpkgname[XBPS_NAME_SIZE];
265 if (!
xbps_pkg_name(curpkgname,
sizeof(curpkgname), pkgver_q)) {
269 if (strcmp(pkgname, curpkgname)) {
271 if (xbps_dictionary_get(curpkgd,
"hold")) {
272 ttype = XBPS_TRANS_HOLD;
277 ttype = XBPS_TRANS_INSTALL;
281 if (xbps_dictionary_get(curpkgd,
"hold")) {
283 ttype = XBPS_TRANS_HOLD;
287 ttype = XBPS_TRANS_UPDATE;
294 rv = add_missing_reqdep(xhp, reqpkg);
295 if (rv != 0 && rv != EEXIST) {
298 }
else if (rv == EEXIST) {
307 }
else if (rv == 1) {
312 if (state == XBPS_PKG_STATE_UNPACKED) {
318 ttype = XBPS_TRANS_CONFIGURE;
319 }
else if (state == XBPS_PKG_STATE_INSTALLED) {
329 xbps_dbg_printf(
"failed to match pattern %s with %s\n", reqpkg, pkgver_q);
333 if (ttype == XBPS_TRANS_UPDATE || ttype == XBPS_TRANS_CONFIGURE) {
338 bool pkgd_auto =
false;
339 xbps_dictionary_get_bool(curpkgd,
"automatic-install", &pkgd_auto);
340 autoinst = pkgd_auto;
342 if (ttype == XBPS_TRANS_CONFIGURE) {
345 xbps_dbg_printf(
"xbps_transaction_pkg_type_set failed for `%s': %s\n", reqpkg, strerror(rv));
348 if (!xbps_transaction_store(xhp, pkgs, curpkgd, autoinst)) {
350 xbps_dbg_printf(
"xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv));
360 if (xbps_dictionary_get(curpkgd,
"repolock")) {
361 const char *repourl = NULL;
363 xbps_dbg_printf(
"`%s' is repolocked, looking at single repository.\n", reqpkg);
364 xbps_dictionary_get_cstring_nocopy(curpkgd,
"repository", &repourl);
365 if (repourl && (repo = xbps_regget_repo(
xhp, repourl))) {
376 if (repopkgd == NULL) {
378 if (errno && errno != ENOENT) {
379 xbps_dbg_printf(
"failed to find pkg for `%s' in rpool: %s\n", reqpkg, strerror(errno));
383 rv = add_missing_reqdep(
xhp, reqpkg);
384 if (rv != 0 && rv != EEXIST) {
387 }
else if (rv == EEXIST) {
398 xbps_dictionary_get_cstring_nocopy(repopkgd,
"pkgver", &pkgver_q);
399 if (!
xbps_pkg_name(reqpkgname,
sizeof(reqpkgname), pkgver_q)) {
410 if (strcmp(pkgname, reqpkgname) == 0) {
419 if (ttype == XBPS_TRANS_UPDATE) {
433 if (xbps_find_pkg_in_array(pkgs, pkgname, XBPS_TRANS_UPDATE)) {
447 if (!xbps_array_add(queued, repopkgd))
450 pkg_rdeps = xbps_dictionary_get(repopkgd,
"run_depends");
451 if (xbps_array_count(pkg_rdeps)) {
457 for (
unsigned short x = 0; x < *depth; x++) {
463 rv = repo_deps(
xhp, pkgs, queued, repopkgd, depth);
465 xbps_dbg_printf(
"Error checking %s for rundeps: %s\n", reqpkg, strerror(rv));
469 if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
470 ttype = XBPS_TRANS_DOWNLOAD;
471 }
else if (xbps_dictionary_get(curpkgd,
"hold")) {
472 ttype = XBPS_TRANS_HOLD;
475 xbps_array_remove(queued, xbps_array_count(queued) - 1);
482 xbps_dbg_printf(
"xbps_transaction_pkg_type_set failed for `%s': %s\n", reqpkg, strerror(rv));
485 if (!xbps_transaction_store(
xhp, pkgs, repopkgd, autoinst)) {
487 xbps_dbg_printf(
"xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv));
491 xbps_object_iterator_release(iter);
501 xbps_dictionary_t pkg_repod)
504 unsigned short depth = 0;
512 queued = xbps_array_create();
516 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &pkgver))
525 rv = repo_deps(
xhp, pkgs, queued, pkg_repod, &depth);
526 xbps_object_release(queued);
Generic XBPS structure handler for initialization.
#define xbps_error_oom()
Log out of memory condition.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
void xbps_dbg_printf_append(const char *fmt,...)
Prints debug messages to stderr.
xbps_dictionary_t xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
int xbps_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t *state)
bool xbps_match_virtual_pkg_in_dict(xbps_dictionary_t pkgd, const char *str)
bool xbps_match_virtual_pkg_in_array(xbps_array_t array, const char *str)
xbps_dictionary_t xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
xbps_dictionary_t xbps_rpool_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_rpool_get_pkg(struct xbps_handle *xhp, const char *pkg)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
bool xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t type)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
const char * xbps_pkgpattern_version(const char *pattern)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
bool xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
bool xbps_remove_string_from_array(xbps_array_t array, const char *str)
int xbps_cmpver(const char *pkg1, const char *pkg2)
int xbps_pkgpattern_match(const char *pkgver, const char *pattern)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern)