33#include "xbps_api_impl.h" 
   56trans_find_pkg(
struct xbps_handle *xhp, 
const char *pkg, 
bool force)
 
   58        xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL, vpkg_pkgdb = NULL;
 
   63        const char *repoloc, *repopkgver, *instpkgver, *pkgname;
 
   64        char buf[XBPS_NAME_SIZE] = {0};
 
   65        bool autoinst = 
false;
 
   83        if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
 
   85                ttype = XBPS_TRANS_DOWNLOAD;
 
   93                        pkg_pkgdb = vpkg_pkgdb;
 
   98                        ttype = XBPS_TRANS_REINSTALL;
 
  100                        ttype = XBPS_TRANS_UPDATE;
 
  102                if (!xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, 
"pkgname", &pkgname)) {
 
  106                if (xbps_dictionary_get(pkg_pkgdb, 
"repolock")) {
 
  109                        xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, 
"repository", &repoloc);
 
  111                        if ((repo = xbps_regget_repo(
xhp, repoloc)) == NULL) {
 
  121                ttype = XBPS_TRANS_INSTALL;
 
  132        xbps_dictionary_get_cstring_nocopy(pkg_repod, 
"pkgver", &repopkgver);
 
  134        if (ttype == XBPS_TRANS_UPDATE) {
 
  139                xbps_dictionary_get_cstring_nocopy(pkg_pkgdb,
 
  140                    "pkgver", &instpkgver);
 
  143                        xbps_dictionary_get_cstring_nocopy(pkg_repod,
 
  144                            "repository", &repoloc);
 
  146                            "(installed: %s) from repository `%s'\n",
 
  147                            repopkgver, instpkgver, repoloc);
 
  150        } 
else if (ttype == XBPS_TRANS_REINSTALL) {
 
  156                xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, 
"pkgver", &instpkgver);
 
  158                        ttype = XBPS_TRANS_UPDATE;
 
  166                if ((obj = xbps_dictionary_get(pkg_pkgdb, 
"automatic-install")))
 
  167                        xbps_dictionary_set(pkg_repod, 
"automatic-install", obj);
 
  168                if ((obj = xbps_dictionary_get(pkg_pkgdb, 
"hold")))
 
  169                        xbps_dictionary_set(pkg_repod, 
"hold", obj);
 
  170                if ((obj = xbps_dictionary_get(pkg_pkgdb, 
"repolock")))
 
  171                        xbps_dictionary_set(pkg_repod, 
"repolock", obj);
 
  176        if ((rv = xbps_transaction_init(
xhp)) != 0)
 
  179        pkgs = xbps_dictionary_get(
xhp->
transd, 
"packages");
 
  184        if (ttype == XBPS_TRANS_UPDATE) {
 
  185                if (xbps_find_pkg_in_array(pkgs, repopkgver, 0)) {
 
  187                            "transaction.\n", repopkgver);
 
  192        if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, 
"pkgname", &pkgname)) {
 
  205                state = XBPS_PKG_STATE_NOT_INSTALLED;
 
  211        if (state == XBPS_PKG_STATE_NOT_INSTALLED)
 
  212                ttype = XBPS_TRANS_INSTALL;
 
  214        if (!force && xbps_dictionary_get(pkg_repod, 
"hold"))
 
  215                ttype = XBPS_TRANS_HOLD;
 
  227        if (ttype == XBPS_TRANS_INSTALL)
 
  228                autoinst = 
xhp->
flags & XBPS_FLAG_INSTALL_AUTO;
 
  230        if (!xbps_transaction_store(
xhp, pkgs, pkg_repod, autoinst)) {
 
  244        xbps_dictionary_t pkgd;
 
  245        const char *pkgver = NULL, *pkgname = NULL;
 
  256        if (!xbps_dictionary_get_cstring_nocopy(pkgd, 
"pkgver", &pkgver)) {
 
  259        if (!xbps_dictionary_get_cstring_nocopy(pkgd, 
"pkgname", &pkgname)) {
 
  263        rv = trans_find_pkg(
xhp, pkgname, 
false);
 
  268                if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
 
  273                for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++)  {
 
  274                        const char *curpkgver = NULL;
 
  275                        char curpkgn[XBPS_NAME_SIZE] = {0};
 
  277                        xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
 
  283                        rv = trans_find_pkg(
xhp, curpkgn, 
false);
 
  284                        xbps_dbg_printf(
"%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv);
 
  285                        if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
 
  298                xhp->
flags |= XBPS_FLAG_FORCE_REMOVE_REVDEPS;
 
  300        } 
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
 
  315        xbps_object_iterator_t iter;
 
  316        xbps_dictionary_t pkgd;
 
  317        bool newpkg_found = 
false;
 
  320        rv = xbps_autoupdate(
xhp);
 
  332        iter = xbps_dictionary_iterator(
xhp->
pkgdb);
 
  335        while ((obj = xbps_object_iterator_next(iter))) {
 
  336                const char *pkgver = NULL;
 
  337                char pkgname[XBPS_NAME_SIZE] = {0};
 
  339                pkgd = xbps_dictionary_get_keysym(
xhp->
pkgdb, obj);
 
  340                if (!xbps_dictionary_get_cstring_nocopy(pkgd, 
"pkgver", &pkgver)) {
 
  347                rv = trans_find_pkg(
xhp, pkgname, 
false);
 
  351                } 
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
 
  359        xbps_object_iterator_release(iter);
 
  361        return newpkg_found ? rv : EEXIST;
 
 
  370        rv = xbps_autoupdate(
xhp);
 
  375                if (strcmp(pkg, 
"xbps"))
 
  388        if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
 
  391        for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++)  {
 
  392                const char *pkgver = NULL;
 
  393                char pkgname[XBPS_NAME_SIZE] = {0};
 
  395                if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
 
  403                rv = trans_find_pkg(
xhp, pkgname, 
false);
 
  405                if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
 
  410        rv = trans_find_pkg(
xhp, pkg, force);
 
 
  421        rv = xbps_autoupdate(
xhp);
 
  425                if (strcmp(pkg, 
"xbps"))
 
  438        if (
xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
 
  441        for (
unsigned int i = 0; i < xbps_array_count(rdeps); i++)  {
 
  442                const char *pkgver = NULL;
 
  443                char pkgname[XBPS_NAME_SIZE] = {0};
 
  445                if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
 
  453                rv = trans_find_pkg(
xhp, pkgname, 
false);
 
  455                if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
 
  459        rv = trans_find_pkg(
xhp, pkg, force);
 
 
  469        xbps_dictionary_t pkgd;
 
  470        xbps_array_t pkgs, orphans, orphans_pkg;
 
  484        if ((rv = xbps_transaction_init(
xhp)) != 0)
 
  487        pkgs = xbps_dictionary_get(
xhp->
transd, 
"packages");
 
  495        if ((orphans_pkg = xbps_array_create()) == NULL)
 
  498        xbps_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
 
  500        xbps_object_release(orphans_pkg);
 
  501        if (xbps_object_type(orphans) != XBPS_TYPE_ARRAY)
 
  504        for (
unsigned int i = 0; i < xbps_array_count(orphans); i++) {
 
  505                obj = xbps_array_get(orphans, i);
 
  507                if (!xbps_transaction_store(
xhp, pkgs, obj, 
false)) {
 
  511        xbps_object_release(orphans);
 
  519        if (!xbps_transaction_store(
xhp, pkgs, pkgd, 
false)) {
 
 
  528        xbps_array_t orphans, pkgs;
 
  533        if (xbps_array_count(orphans) == 0) {
 
  540        if ((rv = xbps_transaction_init(
xhp)) != 0)
 
  543        pkgs = xbps_dictionary_get(
xhp->
transd, 
"packages");
 
  547        for (
unsigned int i = 0; i < xbps_array_count(orphans); i++) {
 
  548                obj = xbps_array_get(orphans, i);
 
  550                if (!xbps_transaction_store(
xhp, pkgs, obj, 
false)) {
 
  557                xbps_object_release(orphans);
 
 
  567        if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
 
  570        if (!xbps_dictionary_get_uint8(pkg_repod, 
"transaction", &r))
 
 
  581        if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
 
  585        case XBPS_TRANS_INSTALL:
 
  586        case XBPS_TRANS_UPDATE:
 
  587        case XBPS_TRANS_CONFIGURE:
 
  588        case XBPS_TRANS_REMOVE:
 
  589        case XBPS_TRANS_REINSTALL:
 
  590        case XBPS_TRANS_HOLD:
 
  591        case XBPS_TRANS_DOWNLOAD:
 
  597        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)