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) {
155 xbps_dbg_printf(
"%s",
"");
156 for (
unsigned short x = 0; x < *depth; x++) {
157 xbps_dbg_printf_append(
" ");
159 xbps_dbg_printf_append(
"%s: requires dependency '%s': ", curpkg ? curpkg :
" ", reqpkg);
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);
173 xbps_dbg_printf_append(
"%s ignored.\n", pkgname);
181 xbps_dbg_printf_append(
"%s is a vpkg provided by %s, ignored.\n", pkgname, curpkg);
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) {
193 xbps_dbg_printf_append(
" (%s queued %d)\n", pkgver_q, ttype_q);
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));
224 xbps_dbg_printf_append(
"not installed.\n");
225 ttype = XBPS_TRANS_INSTALL;
226 state = XBPS_PKG_STATE_NOT_INSTALLED;
232 xbps_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
244 xbps_dbg_printf_append(
"[virtual] satisfied by `%s'.\n", pkgver_q);
249 char curpkgname[XBPS_NAME_SIZE];
253 if (!
xbps_pkg_name(curpkgname,
sizeof(curpkgname), pkgver_q)) {
257 if (strcmp(pkgname, curpkgname)) {
258 xbps_dbg_printf_append(
"not installed `%s (vpkg)'", pkgver_q);
259 if (xbps_dictionary_get(curpkgd,
"hold")) {
260 ttype = XBPS_TRANS_HOLD;
261 xbps_dbg_printf_append(
" on hold state! ignoring package.\n");
264 xbps_dbg_printf_append(
"\n");
265 ttype = XBPS_TRANS_INSTALL;
268 xbps_dbg_printf_append(
"installed `%s', must be updated", pkgver_q);
269 if (xbps_dictionary_get(curpkgd,
"hold")) {
270 xbps_dbg_printf_append(
" on hold state! ignoring package.\n");
271 ttype = XBPS_TRANS_HOLD;
274 xbps_dbg_printf_append(
"\n");
275 ttype = XBPS_TRANS_UPDATE;
282 rv = add_missing_reqdep(xhp, reqpkg);
283 if (rv != 0 && rv != EEXIST) {
284 xbps_dbg_printf(
"`%s': add_missing_reqdep failed\n", reqpkg);
286 }
else if (rv == EEXIST) {
287 xbps_dbg_printf(
"`%s' missing dep already added.\n", reqpkg);
291 xbps_dbg_printf(
"`%s' added into the missing deps array.\n", reqpkg);
295 }
else if (rv == 1) {
300 if (state == XBPS_PKG_STATE_UNPACKED) {
305 xbps_dbg_printf_append(
"installed `%s', must be configured.\n", pkgver_q);
306 ttype = XBPS_TRANS_CONFIGURE;
307 }
else if (state == XBPS_PKG_STATE_INSTALLED) {
312 xbps_dbg_printf_append(
"installed `%s'.\n", pkgver_q);
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);
351 xbps_dbg_printf(
"`%s': add_missing_reqdep failed\n",
reqpkg);
354 xbps_dbg_printf(
"`%s' missing dep already added.\n",
reqpkg);
358 xbps_dbg_printf(
"`%s' added into the missing deps array.\n",
reqpkg);
377 xbps_dbg_printf_append(
"[ignoring wrong dependency %s (depends on itself)]\n",
reqpkg);
385 if (
ttype == XBPS_TRANS_UPDATE) {
399 if (xbps_find_pkg_in_array(
pkgs, pkgname, XBPS_TRANS_UPDATE)) {
418 xbps_dbg_printf(
"%s",
"");
419 for (
unsigned short x = 0;
x < *
depth;
x++) {
420 xbps_dbg_printf_append(
" ");
422 xbps_dbg_printf_append(
"%s: finding dependencies:\n",
pkgver_q);
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) {
450 xbps_dbg_printf(
"xbps_transaction_pkg_type_set failed for `%s': %s\n",
reqpkg,
strerror(
rv));
455 xbps_dbg_printf(
"xbps_transaction_store failed for `%s': %s\n",
reqpkg,
strerror(
rv));
459 xbps_object_iterator_release(
iter);
472 unsigned short depth = 0;
478 xbps_dictionary_get_cstring_nocopy(
pkg_repod,
"pkgver", &pkgver);
479 xbps_dbg_printf(
"Finding required dependencies for '%s':\n", pkgver);
Generic XBPS structure handler for initialization.
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)