34 #include "xbps_api_impl.h"
37 xbps_transaction_package_replace(
struct xbps_handle *xhp)
39 prop_array_t replaces, unsorted;
40 prop_dictionary_t instd, reppkgd, filesd;
41 prop_object_t obj, obj2;
42 prop_object_iterator_t iter;
43 const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
48 unsorted = prop_dictionary_get(xhp->
transd,
"unsorted_deps");
50 for (i = 0; i < prop_array_count(unsorted); i++) {
51 obj = prop_array_get(unsorted, i);
52 replaces = prop_dictionary_get(obj,
"replaces");
53 if (replaces == NULL || prop_array_count(replaces) == 0)
56 iter = prop_array_iterator(replaces);
59 while ((obj2 = prop_object_iterator_next(iter)) != NULL) {
60 pattern = prop_string_cstring_nocopy(obj2);
69 prop_dictionary_get_cstring_nocopy(obj,
71 prop_dictionary_get_cstring_nocopy(obj,
73 prop_dictionary_get_cstring_nocopy(instd,
74 "pkgname", &curpkgname);
75 prop_dictionary_get_cstring_nocopy(instd,
76 "pkgver", &curpkgver);
81 if (strcmp(pkgname, curpkgname) == 0)
85 "Package `%s' will be replaced by `%s', "
86 "matched with `%s'\n", curpkgver, pkgver, pattern);
88 prop_dictionary_get_bool(instd,
89 "automatic-install", &instd_auto);
95 if ((reppkgd = xbps_find_pkg_in_array(unsorted, curpkgname)) ||
96 (reppkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, curpkgname))) {
100 prop_dictionary_set_bool(instd,
101 "remove-and-update",
true);
102 prop_dictionary_set_bool(reppkgd,
103 "automatic-install", instd_auto);
104 prop_dictionary_set_bool(reppkgd,
105 "skip-obsoletes",
true);
106 xbps_array_replace_dict_by_name(unsorted,
107 reppkgd, curpkgname);
118 prop_dictionary_set_bool(obj,
119 "automatic-install", instd_auto);
122 prop_dictionary_get_bool(obj,
"softreplace", &sr);
124 prop_dictionary_set_bool(obj,
125 "automatic-install", instd_auto);
126 prop_dictionary_set_bool(instd,
127 "softreplace",
true);
130 filesd = prop_dictionary_internalize_from_zfile(buf);
132 assert(filesd != NULL);
135 if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
137 prop_object_release(filesd);
138 prop_object_iterator_release(iter);
141 prop_object_release(filesd);
148 prop_dictionary_set_cstring_nocopy(instd,
149 "transaction",
"remove");
150 prop_array_add(unsorted, instd);
152 prop_object_iterator_release(iter);