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;
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 for (
unsigned int j = 0; j < xbps_array_count(replaces); j++) {
73 const char *curpkgver = NULL, *pattern = NULL;
74 char curpkgname[XBPS_NAME_SIZE] = {0};
75 bool instd_auto =
false, hold =
false;
78 if(!xbps_array_get_cstring_nocopy(replaces, j, &pattern))
89 if (!xbps_dictionary_get_cstring_nocopy(instd,
"pkgver", &curpkgver)) {
90 xbps_object_iterator_release(iter);
94 if (xbps_dictionary_get_bool(instd,
"hold", &hold) && hold)
98 xbps_object_iterator_release(iter);
105 if (strcmp(pkgname, curpkgname) == 0) {
111 xbps_dictionary_get_bool(instd,
"automatic-install", &instd_auto);
112 reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, 0);
115 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD)
117 if (!xbps_dictionary_get_cstring_nocopy(reppkgd,
118 "pkgver", &curpkgver)) {
119 xbps_object_iterator_release(iter);
131 xbps_dictionary_remove(obj,
"automatic-install");
133 if (!xbps_dictionary_set_bool(reppkgd,
"replaced",
true)) {
134 xbps_object_iterator_release(iter);
138 xbps_object_iterator_release(iter);
141 if (xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname) != 0) {
142 xbps_object_iterator_release(iter);
146 "Package `%s' in transaction will be "
147 "replaced by `%s', matched with `%s'\n",
148 curpkgver, pkgver, pattern);
158 xbps_dictionary_remove(obj,
"automatic-install");
166 xbps_object_iterator_release(iter);
169 if (!xbps_dictionary_set_bool(instd,
"replaced",
true)) {
170 xbps_object_iterator_release(iter);
173 if (!xbps_array_add_first(pkgs, instd)) {
174 xbps_object_iterator_release(iter);
178 "Package `%s' will be replaced by `%s', "
179 "matched with `%s'\n", curpkgver, pkgver, pattern);
181 xbps_object_iterator_release(iter);
Generic XBPS structure handler for initialization.
void xbps_dbg_printf(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)
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)