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))
88 ((instd = xbps_find_pkg_in_array(pkgs, pattern, XBPS_TRANS_INSTALL)) == NULL))
91 if (!xbps_dictionary_get_cstring_nocopy(instd,
"pkgver", &curpkgver)) {
92 xbps_object_iterator_release(iter);
96 if (xbps_dictionary_get_bool(instd,
"hold", &hold) && hold)
100 xbps_object_iterator_release(iter);
107 if (strcmp(pkgname, curpkgname) == 0) {
113 xbps_dictionary_get_bool(instd,
"automatic-install", &instd_auto);
114 reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, 0);
117 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD)
119 if (!xbps_dictionary_get_cstring_nocopy(reppkgd,
120 "pkgver", &curpkgver)) {
121 xbps_object_iterator_release(iter);
133 xbps_dictionary_remove(obj,
"automatic-install");
135 if (!xbps_dictionary_set_bool(reppkgd,
"replaced",
true)) {
136 xbps_object_iterator_release(iter);
140 xbps_object_iterator_release(iter);
143 if (xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname) != 0) {
144 xbps_object_iterator_release(iter);
149 "Package `%s' in transaction will be "
150 "replaced by `%s', matched with `%s'\n",
151 curpkgver, pkgver, pattern);
161 xbps_dictionary_remove(obj,
"automatic-install");
169 xbps_object_iterator_release(iter);
172 if (!xbps_dictionary_set_bool(instd,
"replaced",
true)) {
173 xbps_object_iterator_release(iter);
176 if (!xbps_array_add_first(pkgs, instd)) {
177 xbps_object_iterator_release(iter);
182 "Package `%s' will be replaced by `%s', "
183 "matched with `%s'\n", curpkgver, pkgver, pattern);
185 xbps_object_iterator_release(iter);
Generic XBPS structure handler for initialization.
void xbps_verbose_printf(const char *,...)
Prints messages to stderr if verbosity is enabled.
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)