31#include <sys/statvfs.h>
33#include "xbps_api_impl.h"
59 xbps_dictionary_t pkg_metad;
60 xbps_object_iterator_t iter;
63 uint64_t rootdir_free_size, tsize, dlsize, instsize, rmsize;
64 uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt, dl_pkgcnt;
67 inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
68 hold_pkgcnt = dl_pkgcnt = 0;
69 tsize = dlsize = instsize = rmsize = 0;
75 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
76 const char *pkgver = NULL, *repo = NULL, *pkgname = NULL;
77 bool preserve =
false;
83 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
84 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgname);
85 xbps_dictionary_get_cstring_nocopy(obj,
"repository", &repo);
86 xbps_dictionary_get_bool(obj,
"preserve", &preserve);
89 if (ttype == XBPS_TRANS_REMOVE) {
91 }
else if (ttype == XBPS_TRANS_CONFIGURE) {
93 }
else if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_REINSTALL) {
95 }
else if (ttype == XBPS_TRANS_UPDATE) {
97 }
else if (ttype == XBPS_TRANS_HOLD) {
101 if ((ttype != XBPS_TRANS_CONFIGURE) && (ttype != XBPS_TRANS_REMOVE) &&
102 (ttype != XBPS_TRANS_HOLD) &&
104 xbps_dictionary_get_uint64(obj,
"filename-size", &tsize);
108 xbps_dictionary_set_bool(obj,
"download",
true);
110 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
114 if (ttype != XBPS_TRANS_REMOVE && ttype != XBPS_TRANS_HOLD &&
115 ttype != XBPS_TRANS_CONFIGURE) {
116 xbps_dictionary_get_uint64(obj,
"installed_size", &tsize);
123 if (ttype == XBPS_TRANS_REMOVE ||
124 ((ttype == XBPS_TRANS_UPDATE) && !preserve)) {
126 if (pkg_metad == NULL)
128 xbps_dictionary_get_uint64(pkg_metad,
129 "installed_size", &tsize);
133 xbps_object_iterator_release(iter);
135 if (instsize > rmsize) {
138 }
else if (rmsize > instsize) {
142 instsize = rmsize = 0;
145 if (!xbps_dictionary_set_uint32(xhp->
transd,
146 "total-install-pkgs", inst_pkgcnt))
148 if (!xbps_dictionary_set_uint32(xhp->
transd,
149 "total-update-pkgs", up_pkgcnt))
151 if (!xbps_dictionary_set_uint32(xhp->
transd,
152 "total-configure-pkgs", cf_pkgcnt))
154 if (!xbps_dictionary_set_uint32(xhp->
transd,
155 "total-remove-pkgs", rm_pkgcnt))
157 if (!xbps_dictionary_set_uint32(xhp->
transd,
158 "total-download-pkgs", dl_pkgcnt))
160 if (!xbps_dictionary_set_uint32(xhp->
transd,
161 "total-hold-pkgs", hold_pkgcnt))
163 if (!xbps_dictionary_set_uint64(xhp->
transd,
164 "total-installed-size", instsize))
166 if (!xbps_dictionary_set_uint64(xhp->
transd,
167 "total-download-size", dlsize))
169 if (!xbps_dictionary_set_uint64(xhp->
transd,
170 "total-removed-size", rmsize))
174 if (statvfs(xhp->
rootdir, &svfs) == -1) {
175 xbps_dbg_printf(
"%s: statvfs failed: %s\n", __func__, strerror(errno));
179 rootdir_free_size = svfs.f_bfree * svfs.f_bsize;
181 if (!xbps_dictionary_set_uint64(xhp->
transd,
182 "disk-free-size", rootdir_free_size))
185 if (instsize > rootdir_free_size)
195 xbps_dictionary_t dict;
200 if ((xhp->
transd = xbps_dictionary_create()) == NULL)
203 if ((array = xbps_array_create()) == NULL) {
204 xbps_object_release(xhp->
transd);
208 if (!xbps_dictionary_set(xhp->
transd,
"packages", array)) {
209 xbps_object_release(xhp->
transd);
213 xbps_object_release(array);
215 if ((array = xbps_array_create()) == NULL) {
216 xbps_object_release(xhp->
transd);
220 if (!xbps_dictionary_set(xhp->
transd,
"missing_deps", array)) {
221 xbps_object_release(xhp->
transd);
225 xbps_object_release(array);
227 if ((array = xbps_array_create()) == NULL) {
228 xbps_object_release(xhp->
transd);
232 if (!xbps_dictionary_set(xhp->
transd,
"missing_shlibs", array)) {
233 xbps_object_release(xhp->
transd);
237 xbps_object_release(array);
239 if ((array = xbps_array_create()) == NULL) {
240 xbps_object_release(xhp->
transd);
244 if (!xbps_dictionary_set(xhp->
transd,
"conflicts", array)) {
245 xbps_object_release(xhp->
transd);
249 xbps_object_release(array);
251 if ((dict = xbps_dictionary_create()) == NULL) {
252 xbps_object_release(xhp->
transd);
256 if (!xbps_dictionary_set(xhp->
transd,
"obsolete_files", dict)) {
257 xbps_object_release(xhp->
transd);
261 xbps_object_release(dict);
263 if ((dict = xbps_dictionary_create()) == NULL) {
264 xbps_object_release(xhp->
transd);
268 if (!xbps_dictionary_set(xhp->
transd,
"remove_files", dict)) {
269 xbps_object_release(xhp->
transd);
273 xbps_object_release(dict);
281 xbps_array_t pkgs, edges;
282 xbps_dictionary_t tpkgd;
286 bool all_on_hold =
true;
288 if ((rv = xbps_transaction_init(xhp)) != 0)
297 if ((edges = xbps_array_create()) == NULL)
300 xbps_dbg_printf(
"%s: processing deps\n", __func__);
305 pkgs = xbps_dictionary_get(xhp->
transd,
"packages");
306 assert(xbps_object_type(pkgs) == XBPS_TYPE_ARRAY);
307 cnt = xbps_array_count(pkgs);
308 for (i = 0; i < cnt; i++) {
309 xbps_dictionary_t pkgd;
312 pkgd = xbps_array_get(pkgs, i);
313 str = xbps_dictionary_get(pkgd,
"pkgver");
316 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD)
319 assert(xbps_object_type(str) == XBPS_TYPE_STRING);
321 if (!xbps_array_add(edges, str)) {
322 xbps_object_release(edges);
325 if ((rv = xbps_transaction_pkg_deps(xhp, pkgs, pkgd)) != 0) {
326 xbps_object_release(edges);
329 if (!xbps_array_add(pkgs, pkgd)) {
330 xbps_object_release(edges);
335 for (i = 0; i < xbps_array_count(edges); i++) {
336 const char *pkgver = NULL;
337 xbps_array_get_cstring_nocopy(edges, i, &pkgver);
338 xbps_remove_pkg_from_array_by_pkgver(pkgs, pkgver);
340 xbps_object_release(edges);
346 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY)
353 xbps_dbg_printf(
"%s: checking on hold pkgs\n", __func__);
354 for (i = 0; i < cnt; i++) {
355 tpkgd = xbps_array_get(pkgs, i);
367 xbps_dbg_printf(
"%s: checking replaces\n", __func__);
368 if (!xbps_transaction_check_replaces(xhp, pkgs)) {
369 xbps_object_release(xhp->
transd);
376 xbps_dbg_printf(
"%s: checking revdeps\n", __func__);
377 if (!xbps_transaction_check_revdeps(xhp, pkgs)) {
378 xbps_object_release(xhp->
transd);
382 if (xbps_dictionary_get(xhp->
transd,
"missing_deps")) {
383 if (xhp->
flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
384 xbps_dbg_printf(
"[trans] continuing with broken reverse dependencies!");
392 xbps_dbg_printf(
"%s: checking conflicts\n", __func__);
393 if (!xbps_transaction_check_conflicts(xhp, pkgs)) {
394 xbps_object_release(xhp->
transd);
398 if (xbps_dictionary_get(xhp->
transd,
"conflicts")) {
404 xbps_dbg_printf(
"%s: checking shlibs\n", __func__);
405 if (!xbps_transaction_check_shlibs(xhp, pkgs)) {
406 xbps_object_release(xhp->
transd);
410 if (xbps_dictionary_get(xhp->
transd,
"missing_shlibs")) {
411 if (xhp->
flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
412 xbps_dbg_printf(
"[trans] continuing with unresolved shared libraries!");
423 xbps_dbg_printf(
"%s: computing stats\n", __func__);
424 if ((rv = compute_transaction_stats(xhp)) != 0) {
430 xbps_dictionary_make_immutable(xhp->
transd);
char rootdir[XBPS_MAXPATH]
Generic XBPS structure handler for initialization.
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
xbps_object_iterator_t xbps_array_iter_from_dict(xbps_dictionary_t dict, const char *key)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
int xbps_transaction_prepare(struct xbps_handle *xhp)
bool xbps_repository_is_remote(const char *uri)
bool xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)