32#include "xbps_api_impl.h"
35pkg_conflicts_trans(
struct xbps_handle *xhp, xbps_array_t array,
36 xbps_dictionary_t pkg_repod)
38 xbps_array_t pkg_cflicts, trans_cflicts;
39 xbps_dictionary_t pkgd, tpkgd;
41 xbps_object_iterator_t iter;
43 const char *cfpkg, *repopkgver, *repopkgname;
50 pkg_cflicts = xbps_dictionary_get(pkg_repod,
"conflicts");
51 if (xbps_array_count(pkg_cflicts) == 0) {
56 if (ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_REMOVE) {
60 trans_cflicts = xbps_dictionary_get(xhp->
transd,
"conflicts");
61 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &repopkgver)) {
64 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgname", &repopkgname)) {
68 iter = xbps_array_iterator(pkg_cflicts);
71 while ((obj = xbps_object_iterator_next(iter))) {
72 const char *pkgver = NULL, *pkgname = NULL;
74 cfpkg = xbps_string_cstring_nocopy(obj);
82 if (xbps_dictionary_get(pkgd,
"hold"))
86 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname)) {
89 if (strcmp(pkgname, repopkgname) == 0) {
92 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
99 if ((tpkgd = xbps_find_pkg_in_array(array, pkgname, 0))) {
101 if (ttype == XBPS_TRANS_INSTALL ||
102 ttype == XBPS_TRANS_UPDATE ||
103 ttype == XBPS_TRANS_REMOVE ||
104 ttype == XBPS_TRANS_HOLD) {
108 xbps_dbg_printf(
"found conflicting installed "
109 "pkg %s with pkg in transaction %s "
110 "(matched by %s [trans])\n", pkgver, repopkgver, cfpkg);
112 "installed pkg %s (matched by %s)",
113 repopkgver, pkgver, cfpkg);
115 xbps_array_add_cstring(trans_cflicts, buf);
123 if ((pkgd = xbps_find_pkg_in_array(array, cfpkg, 0)) ||
124 (pkgd = xbps_find_virtualpkg_in_array(xhp, array, cfpkg, 0))) {
127 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
131 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname)) {
134 if (strcmp(pkgname, repopkgname) == 0) {
137 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
140 xbps_dbg_printf(
"found conflicting pkgs in "
141 "transaction %s <-> %s (matched by %s [trans])\n",
142 pkgver, repopkgver, cfpkg);
144 "%s in transaction (matched by %s)",
145 repopkgver, pkgver, cfpkg);
147 xbps_array_add_cstring(trans_cflicts, buf);
153 xbps_object_iterator_release(iter);
157pkgdb_conflicts_cb(
struct xbps_handle *xhp, xbps_object_t obj,
158 const char *key UNUSED,
void *arg,
bool *done UNUSED)
160 xbps_array_t pkg_cflicts, trans_cflicts, pkgs = arg;
161 xbps_dictionary_t pkgd;
163 xbps_object_iterator_t iter;
165 const char *cfpkg, *repopkgver, *repopkgname;
169 pkg_cflicts = xbps_dictionary_get(obj,
"conflicts");
170 if (xbps_array_count(pkg_cflicts) == 0)
173 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &repopkgver)) {
176 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgname", &repopkgname)) {
181 if (xbps_find_pkg_in_array(pkgs, repopkgname, 0)) {
185 trans_cflicts = xbps_dictionary_get(xhp->
transd,
"conflicts");
186 iter = xbps_array_iterator(pkg_cflicts);
189 while ((obj2 = xbps_object_iterator_next(iter))) {
190 const char *pkgver = NULL, *pkgname = NULL;
192 cfpkg = xbps_string_cstring_nocopy(obj2);
193 if ((pkgd = xbps_find_pkg_in_array(pkgs, cfpkg, 0)) ||
194 (pkgd = xbps_find_virtualpkg_in_array(xhp, pkgs, cfpkg, 0))) {
197 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
201 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname)) {
205 if (strcmp(pkgname, repopkgname) == 0) {
208 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
212 xbps_dbg_printf(
"found conflicting pkgs in "
213 "transaction %s <-> %s (matched by %s [pkgdb])\n",
214 pkgver, repopkgver, cfpkg);
216 "%s in transaction (matched by %s)",
217 repopkgver, pkgver, cfpkg);
219 xbps_array_add_cstring(trans_cflicts, buf);
225 xbps_object_iterator_release(iter);
230xbps_transaction_check_conflicts(
struct xbps_handle *xhp, xbps_array_t pkgs)
236 for (i = 0; i < xbps_array_count(pkgs); i++) {
237 pkg_conflicts_trans(xhp, pkgs, xbps_array_get(pkgs, i));
244 array = xbps_dictionary_get(xhp->
transd,
"conflicts");
245 if (xbps_array_count(array) == 0) {
246 xbps_dictionary_remove(xhp->
transd,
"conflicts");
Generic XBPS structure handler for initialization.
int xbps_pkgdb_foreach_cb_multi(struct xbps_handle *xhp, int(*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *), void *arg)
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)
bool xbps_match_string_in_array(xbps_array_t array, const char *val)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf