35#include "xbps_api_impl.h"
37static xbps_dictionary_t
38get_pkg_in_array(xbps_array_t array,
const char *str,
xbps_trans_type_t tt,
bool virtual)
41 xbps_object_iterator_t iter;
48 iter = xbps_array_iterator(array);
52 while ((obj = xbps_object_iterator_next(iter))) {
53 const char *pkgver = NULL;
54 char pkgname[XBPS_NAME_SIZE] = {0};
56 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
75 if (strcmp(str, pkgver) == 0) {
84 if (strcmp(pkgname, str) == 0) {
90 xbps_object_iterator_release(iter);
93 if (found && tt && (ttype != tt)) {
103xbps_dictionary_t HIDDEN
106 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
109 return get_pkg_in_array(a, s, tt,
false);
112xbps_dictionary_t HIDDEN
113xbps_find_virtualpkg_in_array(
struct xbps_handle *x,
118 xbps_dictionary_t pkgd;
122 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
125 if ((vpkg = vpkg_user_conf(x, s,
false))) {
126 if ((pkgd = get_pkg_in_array(a, vpkg, tt,
true)))
130 return get_pkg_in_array(a, s, tt,
true);
133static xbps_dictionary_t
134match_pkg_by_pkgver(xbps_dictionary_t repod,
const char *p)
136 xbps_dictionary_t d = NULL;
137 const char *pkgver = NULL;
138 char pkgname[XBPS_NAME_SIZE] = {0};
147 d = xbps_dictionary_get(repod, pkgname);
149 xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver);
150 if (strcmp(pkgver, p)) {
159static xbps_dictionary_t
160match_pkg_by_pattern(xbps_dictionary_t repod,
const char *p)
162 xbps_dictionary_t d = NULL;
163 const char *pkgver = NULL;
164 char pkgname[XBPS_NAME_SIZE] = {0};
172 return match_pkg_by_pkgver(repod, p);
177 d = xbps_dictionary_get(repod, pkgname);
179 xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver);
191vpkg_user_conf(
struct xbps_handle *xhp,
const char *vpkg,
bool only_conf)
195 xbps_object_iterator_t iter;
196 const char *pkg = NULL;
207 (void)xbps_pkgdb_init(xhp);
213 iter = xbps_dictionary_iterator(d);
216 while ((obj = xbps_object_iterator_next(iter))) {
218 char buf[XBPS_NAME_SIZE] = {0};
219 char *vpkgver = NULL, *vpkgname = NULL;
220 const char *vpkg_conf = NULL;
222 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
223 rpkg = xbps_dictionary_get_keysym(xhp->vpkgd, obj);
224 pkg = xbps_string_cstring_nocopy(rpkg);
230 vpkgname = strdup(buf);
232 vpkgname = strdup(vpkg_conf);
255 if (strcmp(buf, vpkgname)) {
260 if (strcmp(vpkg, vpkgname)) {
265 xbps_dbg_printf(
"%s: vpkg_conf %s pkg %s vpkgname %s\n", __func__, vpkg_conf, pkg, vpkgname);
270 xbps_object_iterator_release(iter);
272 return found ? pkg : NULL;
275xbps_dictionary_t HIDDEN
276xbps_find_virtualpkg_in_conf(
struct xbps_handle *xhp,
280 xbps_dictionary_t pkgd;
284 vpkg = vpkg_user_conf(xhp, pkg,
true);
287 pkgd = match_pkg_by_pattern(d, vpkg);
289 pkgd = match_pkg_by_pkgver(d, vpkg);
291 pkgd = xbps_dictionary_get(d, vpkg);
300xbps_dictionary_t HIDDEN
301xbps_find_virtualpkg_in_dict(
struct xbps_handle *xhp,
306 xbps_object_iterator_t iter;
307 xbps_dictionary_t pkgd = NULL;
311 vpkg = vpkg_user_conf(xhp, pkg,
false);
314 pkgd = match_pkg_by_pattern(d, vpkg);
316 pkgd = match_pkg_by_pkgver(d, vpkg);
318 pkgd = xbps_dictionary_get(d, vpkg);
324 iter = xbps_dictionary_iterator(d);
327 while ((obj = xbps_object_iterator_next(iter))) {
328 pkgd = xbps_dictionary_get_keysym(d, obj);
330 xbps_object_iterator_release(iter);
334 xbps_object_iterator_release(iter);
339xbps_dictionary_t HIDDEN
340xbps_find_pkg_in_dict(xbps_dictionary_t d,
const char *pkg)
342 xbps_dictionary_t pkgd = NULL;
345 pkgd = match_pkg_by_pattern(d, pkg);
347 pkgd = match_pkg_by_pkgver(d, pkg);
349 pkgd = xbps_dictionary_get(d, pkg);
Generic XBPS structure handler for initialization.
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)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
const char * xbps_pkgpattern_version(const char *pattern)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
int xbps_pkgpattern_match(const char *pkgver, const char *pattern)
const char * xbps_pkg_version(const char *pkg)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern)