34#include "xbps/xbps_array.h"
35#include "xbps/xbps_dictionary.h"
36#include "xbps_api_impl.h"
57 struct xbps_handle *xhp;
58 struct shlib_entry *entries;
59 xbps_dictionary_t seen;
63static struct shlib_entry *
64shlib_entry_find(
struct shlib_entry *head,
const char *name)
66 struct shlib_entry *res = NULL;
67 HASH_FIND_STR(head, name, res);
71static struct shlib_entry *
72shlib_entry_get(
struct shlib_ctx *ctx,
const char *name)
74 struct shlib_entry *res = shlib_entry_find(ctx->entries, name);
77 res = calloc(1,
sizeof(*res));
84 HASH_ADD_STR(ctx->entries, name, res);
89collect_shlib_array(
struct shlib_ctx *ctx, xbps_array_t array)
91 for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
92 struct shlib_entry *entry;
93 const char *shlib = NULL;
94 if (!xbps_array_get_cstring_nocopy(array, i, &shlib))
96 entry = shlib_entry_get(ctx, shlib);
104collect_shlibs(
struct shlib_ctx *ctx, xbps_array_t pkgs)
107 xbps_object_iterator_t iter;
108 xbps_bool_t placeholder;
111 placeholder = xbps_bool_create(
true);
117 ctx->seen = xbps_dictionary_create();
123 for (
unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
125 xbps_dictionary_t pkgd = xbps_array_get(pkgs, i);
130 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname)) {
134 if (!xbps_dictionary_set(ctx->seen, pkgname, placeholder)) {
142 array = xbps_dictionary_get(pkgd,
"shlib-provides");
144 int r = collect_shlib_array(ctx, array);
150 iter = xbps_dictionary_iterator(ctx->xhp->
pkgdb);
156 while ((obj = xbps_object_iterator_next(iter))) {
158 xbps_dictionary_t pkgd;
159 const char *pkgname = NULL;
161 pkgname = xbps_dictionary_keysym_cstring_nocopy(obj);
163 if (strncmp(pkgname,
"_XBPS_", 6) == 0)
166 pkgd = xbps_dictionary_get_keysym(ctx->xhp->
pkgdb, obj);
168 if (xbps_dictionary_get(ctx->seen, pkgname))
171 array = xbps_dictionary_get(pkgd,
"shlib-provides");
173 int r = collect_shlib_array(ctx, array);
179 xbps_object_iterator_release(iter);
184check_shlibs(
struct shlib_ctx *ctx, xbps_array_t pkgs)
186 xbps_object_iterator_t iter;
189 for (
unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
191 xbps_dictionary_t pkgd = xbps_array_get(pkgs, i);
194 if (ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_REMOVE)
197 array = xbps_dictionary_get(pkgd,
"shlib-requires");
200 for (
unsigned int j = 0; j < xbps_array_count(array); j++) {
201 const char *pkgver = NULL;
202 const char *shlib = NULL;
204 if (!xbps_array_get_cstring_nocopy(array, j, &shlib))
206 if (shlib_entry_find(ctx->entries, shlib))
208 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver))
211 "%s: broken, unresolvable shlib `%s'",
213 if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) {
220 iter = xbps_dictionary_iterator(ctx->xhp->
pkgdb);
226 while ((obj = xbps_object_iterator_next(iter))) {
228 xbps_dictionary_t pkgd;
229 const char *pkgname = NULL;
231 pkgname = xbps_dictionary_keysym_cstring_nocopy(obj);
233 if (strncmp(pkgname,
"_XBPS_", 6) == 0)
236 pkgd = xbps_dictionary_get_keysym(ctx->xhp->
pkgdb, obj);
238 if (xbps_dictionary_get(ctx->seen, pkgname))
241 array = xbps_dictionary_get(pkgd,
"shlib-requires");
244 for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
245 const char *pkgver = NULL;
246 const char *shlib = NULL;
248 if (!xbps_array_get_cstring_nocopy(array, i, &shlib))
250 if (shlib_entry_find(ctx->entries, shlib))
252 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver))
255 "%s: broken, unresolvable shlib `%s'", pkgver,
257 if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) {
264 xbps_object_iterator_release(iter);
269xbps_transaction_check_shlibs(
struct xbps_handle *xhp, xbps_array_t pkgs)
271 struct shlib_entry *entry, *tmp;
272 struct shlib_ctx ctx = { .xhp = xhp };
275 ctx.missing = xbps_dictionary_get(xhp->
transd,
"missing_shlibs");
277 r = collect_shlibs(&ctx, pkgs);
281 r = check_shlibs(&ctx, pkgs);
285 if (xbps_array_count(ctx.missing) == 0)
286 xbps_dictionary_remove(xhp->
transd,
"missing_shlibs");
290 HASH_ITER(hh, ctx.entries, entry, tmp) {
291 HASH_DEL(ctx.entries, entry);
295 xbps_object_release(ctx.seen);
Generic XBPS structure handler for initialization.
void void xbps_error_printf(const char *fmt,...)
Prints error messages to stderr.
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf