32#include "xbps_api_impl.h"
65 xbps_array_t array = NULL;
67 xbps_object_iterator_t iter;
69 if (xbps_pkgdb_init(xhp) != 0)
72 if ((array = xbps_array_create()) == NULL)
77 iter = xbps_dictionary_iterator(xhp->
pkgdb);
84 while ((obj = xbps_object_iterator_next(iter))) {
86 xbps_dictionary_t pkgd;
87 unsigned int cnt = 0, revdepscnt = 0;
88 const char *pkgver = NULL;
89 bool automatic =
false;
91 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
92 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
96 xbps_dbg_printf(
" %s checking %s\n", __func__, pkgver);
97 xbps_dictionary_get_bool(pkgd,
"automatic-install", &automatic);
99 xbps_dbg_printf(
" %s skipped (!automatic)\n", pkgver);
102 if (xbps_find_pkg_in_array(array, pkgver, 0)) {
103 xbps_dbg_printf(
" %s orphan (queued)\n", pkgver);
107 revdepscnt = xbps_array_count(revdeps);
109 if (revdepscnt == 0) {
111 xbps_array_add(array, pkgd);
112 xbps_dbg_printf(
" %s orphan (automatic and !revdeps)\n", pkgver);
116 for (
unsigned int i = 0; i < revdepscnt; i++) {
117 const char *revdepver = NULL;
119 xbps_array_get_cstring_nocopy(revdeps, i, &revdepver);
120 if (xbps_find_pkg_in_array(array, revdepver, 0))
123 if (cnt == revdepscnt) {
125 xbps_array_add(array, pkgd);
126 xbps_dbg_printf(
" %s orphan (automatic and all revdeps)\n", pkgver);
130 xbps_dbg_printf(
"orphans pkgdb iter: added %s\n", added ?
"true" :
"false");
131 xbps_object_iterator_reset(iter);
135 xbps_object_iterator_release(iter);
143 for (
unsigned int i = 0; i < xbps_array_count(orphans_user); i++) {
144 xbps_dictionary_t pkgd;
145 const char *pkgver = NULL;
147 xbps_array_get_cstring_nocopy(orphans_user, i, &pkgver);
151 xbps_array_add(array, pkgd);
154 for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
156 xbps_dictionary_t pkgd;
157 const char *pkgver = NULL;
158 unsigned int cnt = 0, reqbycnt = 0;
160 pkgd = xbps_array_get(array, i);
161 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
163 if (xbps_array_count(rdeps) == 0) {
167 xbps_dbg_printf(
" processing rdeps for %s\n", pkgver);
168 for (
unsigned int x = 0; x < xbps_array_count(rdeps); x++) {
170 xbps_dictionary_t deppkgd;
171 const char *deppkgver = NULL;
172 bool automatic =
false;
175 xbps_array_get_cstring_nocopy(rdeps, x, &deppkgver);
176 if (xbps_find_pkg_in_array(array, deppkgver, 0)) {
177 xbps_dbg_printf(
" rdep %s already queued\n", deppkgver);
181 xbps_dictionary_get_bool(deppkgd,
"automatic-install", &automatic);
183 xbps_dbg_printf(
" rdep %s skipped (!automatic)\n", deppkgver);
188 reqbycnt = xbps_array_count(reqby);
189 for (
unsigned int j = 0; j < reqbycnt; j++) {
190 const char *reqbydep = NULL;
192 xbps_array_get_cstring_nocopy(reqby, j, &reqbydep);
193 xbps_dbg_printf(
" %s processing revdep %s\n", pkgver, reqbydep);
194 if (xbps_find_pkg_in_array(array, reqbydep, 0))
197 if (cnt == reqbycnt) {
198 xbps_array_add(array, deppkgd);
199 xbps_dbg_printf(
" added %s orphan\n", deppkgver);
Generic XBPS structure handler for initialization.
xbps_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user)
xbps_array_t xbps_pkgdb_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg)
xbps_array_t xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)