32#include "xbps_api_impl.h"
55trans_find_pkg(
struct xbps_handle *xhp,
const char *pkg,
bool force)
57 char buf[XBPS_NAME_SIZE];
58 xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL, vpkg_pkgdb = NULL;
63 const char *repoloc, *repopkgver, *instpkgver, *pkgname;
64 bool autoinst =
false;
82 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
84 ttype = XBPS_TRANS_DOWNLOAD;
92 pkg_pkgdb = vpkg_pkgdb;
95 if (!xbps_dictionary_get_cstring_nocopy(
96 pkg_pkgdb,
"pkgname", &pkg)) {
105 ttype = XBPS_TRANS_REINSTALL;
107 ttype = XBPS_TRANS_UPDATE;
109 if (xbps_dictionary_get(pkg_pkgdb,
"repolock")) {
112 xbps_dictionary_get_cstring_nocopy(pkg_pkgdb,
"repository", &repoloc);
114 if ((repo = xbps_regget_repo(
xhp, repoloc)) == NULL) {
124 ttype = XBPS_TRANS_INSTALL;
135 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &repopkgver);
137 if (ttype == XBPS_TRANS_UPDATE) {
142 xbps_dictionary_get_cstring_nocopy(pkg_pkgdb,
143 "pkgver", &instpkgver);
146 xbps_dictionary_get_cstring_nocopy(pkg_repod,
147 "repository", &repoloc);
149 "(installed: %s) from repository `%s'\n",
150 repopkgver, instpkgver, repoloc);
153 }
else if (ttype == XBPS_TRANS_REINSTALL) {
159 xbps_dictionary_get_cstring_nocopy(pkg_pkgdb,
"pkgver", &instpkgver);
161 ttype = XBPS_TRANS_UPDATE;
169 if ((obj = xbps_dictionary_get(pkg_pkgdb,
"automatic-install")))
170 xbps_dictionary_set(pkg_repod,
"automatic-install", obj);
171 if ((obj = xbps_dictionary_get(pkg_pkgdb,
"hold")))
172 xbps_dictionary_set(pkg_repod,
"hold", obj);
173 if ((obj = xbps_dictionary_get(pkg_pkgdb,
"repolock")))
174 xbps_dictionary_set(pkg_repod,
"repolock", obj);
179 if ((rv = xbps_transaction_init(
xhp)) != 0)
182 pkgs = xbps_dictionary_get(
xhp->
transd,
"packages");
187 if (ttype == XBPS_TRANS_UPDATE) {
188 if (xbps_find_pkg_in_array(pkgs, repopkgver, 0)) {
190 "transaction.\n", repopkgver);
195 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgname", &pkgname)) {
208 state = XBPS_PKG_STATE_NOT_INSTALLED;
214 if (state == XBPS_PKG_STATE_NOT_INSTALLED)
215 ttype = XBPS_TRANS_INSTALL;
217 if (!force && xbps_dictionary_get(pkg_repod,
"hold"))
218 ttype = XBPS_TRANS_HOLD;
230 if (ttype == XBPS_TRANS_INSTALL)
231 autoinst =
xhp->
flags & XBPS_FLAG_INSTALL_AUTO;
233 if (!xbps_transaction_store(
xhp, pkgs, pkg_repod, autoinst)) {
247 xbps_dictionary_t pkgd;
248 const char *pkgver = NULL, *pkgname = NULL;
259 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
262 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname)) {
266 rv = trans_find_pkg(
xhp, pkgname,
false);
271 if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
276 for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
277 const char *curpkgver = NULL;
278 char curpkgn[XBPS_NAME_SIZE] = {0};
280 xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
286 rv = trans_find_pkg(
xhp, curpkgn,
false);
287 xbps_dbg_printf(
"%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv);
288 if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
301 xhp->
flags |= XBPS_FLAG_FORCE_REMOVE_REVDEPS;
303 }
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
318 xbps_object_iterator_t iter;
319 xbps_dictionary_t pkgd;
320 bool newpkg_found =
false;
323 rv = xbps_autoupdate(
xhp);
335 iter = xbps_dictionary_iterator(
xhp->
pkgdb);
338 while ((obj = xbps_object_iterator_next(iter))) {
339 const char *pkgver = NULL;
340 char pkgname[XBPS_NAME_SIZE] = {0};
342 pkgd = xbps_dictionary_get_keysym(
xhp->
pkgdb, obj);
343 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
350 rv = trans_find_pkg(
xhp, pkgname,
false);
354 }
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
362 xbps_object_iterator_release(iter);
364 return newpkg_found ? rv : EEXIST;
373 rv = xbps_autoupdate(
xhp);
378 if (strcmp(pkg,
"xbps"))
391 if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
394 for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
395 const char *pkgver = NULL;
396 char pkgname[XBPS_NAME_SIZE] = {0};
398 if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
406 rv = trans_find_pkg(
xhp, pkgname,
false);
408 if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
413 rv = trans_find_pkg(
xhp, pkg, force);
424 rv = xbps_autoupdate(
xhp);
428 if (strcmp(pkg,
"xbps"))
441 if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
444 for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
445 const char *pkgver = NULL;
446 char pkgname[XBPS_NAME_SIZE] = {0};
448 if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
456 rv = trans_find_pkg(
xhp, pkgname,
false);
458 if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
462 rv = trans_find_pkg(
xhp, pkg, force);
472 xbps_dictionary_t pkgd;
473 xbps_array_t pkgs, orphans, orphans_pkg;
487 if ((rv = xbps_transaction_init(
xhp)) != 0)
490 pkgs = xbps_dictionary_get(
xhp->
transd,
"packages");
498 if ((orphans_pkg = xbps_array_create()) == NULL)
501 xbps_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
503 xbps_object_release(orphans_pkg);
504 if (xbps_object_type(orphans) != XBPS_TYPE_ARRAY)
507 for (
unsigned int i = 0; i < xbps_array_count(orphans); i++) {
508 obj = xbps_array_get(orphans, i);
510 if (!xbps_transaction_store(
xhp, pkgs, obj,
false)) {
514 xbps_object_release(orphans);
522 if (!xbps_transaction_store(
xhp, pkgs, pkgd,
false)) {
531 xbps_array_t orphans, pkgs;
536 if (xbps_array_count(orphans) == 0) {
543 if ((rv = xbps_transaction_init(
xhp)) != 0)
546 pkgs = xbps_dictionary_get(
xhp->
transd,
"packages");
550 for (
unsigned int i = 0; i < xbps_array_count(orphans); i++) {
551 obj = xbps_array_get(orphans, i);
553 if (!xbps_transaction_store(
xhp, pkgs, obj,
false)) {
560 xbps_object_release(orphans);
570 if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
573 if (!xbps_dictionary_get_uint8(pkg_repod,
"transaction", &r))
584 if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
588 case XBPS_TRANS_INSTALL:
589 case XBPS_TRANS_UPDATE:
590 case XBPS_TRANS_CONFIGURE:
591 case XBPS_TRANS_REMOVE:
592 case XBPS_TRANS_REINSTALL:
593 case XBPS_TRANS_HOLD:
594 case XBPS_TRANS_DOWNLOAD:
600 if (!xbps_dictionary_set_uint8(pkg_repod,
"transaction", r))
Generic XBPS structure handler for initialization.
void xbps_error_printf(const char *fmt,...)
Prints error messages to stderr.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
xbps_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans)
xbps_dictionary_t xbps_pkgdb_get_virtualpkg(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)
int xbps_pkg_state_installed(struct xbps_handle *xhp, const char *pkgname, pkg_state_t *state)
int xbps_set_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t state)
xbps_dictionary_t xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
xbps_dictionary_t xbps_rpool_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_rpool_get_pkg(struct xbps_handle *xhp, const char *pkg)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
int xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
int xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp)
int xbps_transaction_remove_pkg(struct xbps_handle *xhp, const char *pkgname, bool recursive)
bool xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t ttype)
int xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
int xbps_transaction_update_packages(struct xbps_handle *xhp)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
bool xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver)
int xbps_cmpver(const char *pkg1, const char *pkg2)