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);
114 xbps_dictionary_t pkg_repod,
115 unsigned short *depth)
117 xbps_array_t pkg_rdeps = NULL, pkg_provides = NULL;
118 xbps_dictionary_t curpkgd = NULL, repopkgd = NULL;
122 xbps_object_iterator_t iter;
123 const char *curpkg = NULL, *reqpkg = NULL, *pkgver_q = NULL;
124 char pkgname[XBPS_NAME_SIZE], reqpkgname[XBPS_NAME_SIZE];
131 if (*depth >= MAX_DEPTH)
134 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &curpkg);
135 pkg_provides = xbps_dictionary_get(pkg_repod,
"provides");
140 pkg_rdeps = xbps_dictionary_get(pkg_repod,
"run_depends");
141 if (xbps_array_count(pkg_rdeps) == 0)
144 iter = xbps_array_iterator(pkg_rdeps);
147 while ((obj = xbps_object_iterator_next(iter))) {
148 bool error =
false, foundvpkg =
false;
149 bool autoinst =
true;
151 ttype = XBPS_TRANS_UNKNOWN;
152 reqpkg = xbps_string_cstring_nocopy(obj);
154 if (xhp->
flags & XBPS_FLAG_DEBUG) {
156 for (
unsigned short x = 0; x < *depth; x++) {
163 xbps_dbg_printf(
"%s: can't guess pkgname for dependency: %s\n", curpkg, reqpkg);
164 xbps_set_cb_state(xhp, XBPS_STATE_INVALID_DEP, ENXIO, NULL,
165 "%s: can't guess pkgname for dependency '%s'", curpkg, reqpkg);
188 if ((curpkgd = xbps_find_pkg_in_array(pkgs, reqpkg, 0)) ||
189 (curpkgd = xbps_find_virtualpkg_in_array(xhp, pkgs, reqpkg, 0))) {
191 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
192 if (ttype_q != XBPS_TRANS_REMOVE && ttype_q != XBPS_TRANS_HOLD) {
206 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
216 if (curpkgd == NULL) {
217 if (errno && errno != ENOENT) {
220 xbps_dbg_printf(
"failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv));
225 ttype = XBPS_TRANS_INSTALL;
226 state = XBPS_PKG_STATE_NOT_INSTALLED;
232 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
249 char curpkgname[XBPS_NAME_SIZE];
253 if (!
xbps_pkg_name(curpkgname,
sizeof(curpkgname), pkgver_q)) {
257 if (strcmp(pkgname, curpkgname)) {
259 if (xbps_dictionary_get(curpkgd,
"hold")) {
260 ttype = XBPS_TRANS_HOLD;
265 ttype = XBPS_TRANS_INSTALL;
269 if (xbps_dictionary_get(curpkgd,
"hold")) {
271 ttype = XBPS_TRANS_HOLD;
275 ttype = XBPS_TRANS_UPDATE;
282 rv = add_missing_reqdep(xhp, reqpkg);
283 if (rv != 0 && rv != EEXIST) {
286 }
else if (rv == EEXIST) {
295 }
else if (rv == 1) {
300 if (state == XBPS_PKG_STATE_UNPACKED) {
306 ttype = XBPS_TRANS_CONFIGURE;
307 }
else if (state == XBPS_PKG_STATE_INSTALLED) {
317 xbps_dbg_printf(
"failed to match pattern %s with %s\n", reqpkg, pkgver_q);
326 if (xbps_dictionary_get(curpkgd,
"repolock")) {
327 const char *repourl = NULL;
329 xbps_dbg_printf(
"`%s' is repolocked, looking at single repository.\n", reqpkg);
330 xbps_dictionary_get_cstring_nocopy(curpkgd,
"repository", &repourl);
331 if (repourl && (repo = xbps_regget_repo(
xhp, repourl))) {
342 if (repopkgd == NULL) {
344 if (errno && errno != ENOENT) {
345 xbps_dbg_printf(
"failed to find pkg for `%s' in rpool: %s\n", reqpkg, strerror(errno));
349 rv = add_missing_reqdep(
xhp, reqpkg);
350 if (rv != 0 && rv != EEXIST) {
353 }
else if (rv == EEXIST) {
364 xbps_dictionary_get_cstring_nocopy(repopkgd,
"pkgver", &pkgver_q);
365 if (!
xbps_pkg_name(reqpkgname,
sizeof(reqpkgname), pkgver_q)) {
376 if (strcmp(pkgname, reqpkgname) == 0) {
385 if (ttype == XBPS_TRANS_UPDATE) {
399 if (xbps_find_pkg_in_array(pkgs, pkgname, XBPS_TRANS_UPDATE)) {
412 pkg_rdeps = xbps_dictionary_get(repopkgd,
"run_depends");
413 if (xbps_array_count(pkg_rdeps)) {
419 for (
unsigned short x = 0; x < *depth; x++) {
425 rv = repo_deps(
xhp, pkgs, repopkgd, depth);
427 xbps_dbg_printf(
"Error checking %s for rundeps: %s\n", reqpkg, strerror(rv));
431 if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
432 ttype = XBPS_TRANS_DOWNLOAD;
433 }
else if (xbps_dictionary_get(curpkgd,
"hold")) {
434 ttype = XBPS_TRANS_HOLD;
436 if (ttype == XBPS_TRANS_UPDATE || ttype == XBPS_TRANS_CONFIGURE) {
441 bool pkgd_auto =
false;
442 xbps_dictionary_get_bool(curpkgd,
"automatic-install", &pkgd_auto);
443 autoinst = pkgd_auto;
450 xbps_dbg_printf(
"xbps_transaction_pkg_type_set failed for `%s': %s\n", reqpkg, strerror(rv));
453 if (!xbps_transaction_store(
xhp, pkgs, repopkgd, autoinst)) {
455 xbps_dbg_printf(
"xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv));
459 xbps_object_iterator_release(iter);
469 xbps_dictionary_t pkg_repod)
472 unsigned short depth = 0;
478 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &pkgver);
484 return repo_deps(
xhp, pkgs, pkg_repod, &depth);
Generic XBPS structure handler for initialization.
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)