34#include "xbps_api_impl.h"
44xbps_transaction_check_replaces(
struct xbps_handle *xhp, xbps_array_t pkgs)
49 for (
unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
50 xbps_array_t replaces;
51 xbps_object_t obj, obj2;
52 xbps_object_iterator_t iter;
53 xbps_dictionary_t instd, reppkgd;
54 const char *pkgver = NULL;
55 char pkgname[XBPS_NAME_SIZE] = {0};
57 obj = xbps_array_get(pkgs, i);
58 replaces = xbps_dictionary_get(obj,
"replaces");
59 if (replaces == NULL || xbps_array_count(replaces) == 0)
62 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
69 iter = xbps_array_iterator(replaces);
72 while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
73 const char *curpkgver = NULL, *pattern = NULL;
74 char curpkgname[XBPS_NAME_SIZE] = {0};
75 bool instd_auto =
false, hold =
false;
78 pattern = xbps_string_cstring_nocopy(obj2);
87 if (!xbps_dictionary_get_cstring_nocopy(instd,
"pkgver", &curpkgver)) {
88 xbps_object_iterator_release(iter);
92 if (xbps_dictionary_get_bool(instd,
"hold", &hold) && hold)
96 xbps_object_iterator_release(iter);
103 if (strcmp(pkgname, curpkgname) == 0) {
109 xbps_dictionary_get_bool(instd,
"automatic-install", &instd_auto);
110 reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, 0);
113 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD)
115 if (!xbps_dictionary_get_cstring_nocopy(reppkgd,
116 "pkgver", &curpkgver)) {
117 xbps_object_iterator_release(iter);
129 xbps_dictionary_remove(obj,
"automatic-install");
131 if (!xbps_dictionary_set_bool(reppkgd,
"replaced",
true)) {
132 xbps_object_iterator_release(iter);
136 xbps_object_iterator_release(iter);
139 if (xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname) != 0) {
140 xbps_object_iterator_release(iter);
144 "Package `%s' in transaction will be "
145 "replaced by `%s', matched with `%s'\n",
146 curpkgver, pkgver, pattern);
156 xbps_dictionary_remove(obj,
"automatic-install");
164 xbps_object_iterator_release(iter);
167 if (!xbps_dictionary_set_bool(instd,
"replaced",
true)) {
168 xbps_object_iterator_release(iter);
171 if (!xbps_array_add_first(pkgs, instd)) {
172 xbps_object_iterator_release(iter);
176 "Package `%s' will be replaced by `%s', "
177 "matched with `%s'\n", curpkgver, pkgver, pattern);
179 xbps_object_iterator_release(iter);
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)
bool xbps_match_virtual_pkg_in_dict(xbps_dictionary_t pkgd, const char *str)
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)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
int xbps_pkgpattern_match(const char *pkgver, const char *pattern)