105        xbps_array_t remove_scripts;
 
  106        xbps_dictionary_t pkgdb_pkgd;
 
  108        xbps_object_iterator_t iter;
 
  110        const char *pkgver = NULL, *pkgname = NULL;
 
  114        setlocale(LC_ALL, 
"");
 
  121        remove_scripts = xbps_array_create();
 
  122        if (remove_scripts == NULL)
 
  123                return errno ? errno : ENOMEM;
 
  125        assert(xbps_object_type(xhp->
transd) == XBPS_TYPE_DICTIONARY);
 
  130                if (errno != EEXIST) {
 
  131                        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
 
  133                            "[trans] cannot create cachedir `%s': %s",
 
  139                xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
 
  141                    "[trans] failed to change dir to cachedir `%s': %s",
 
  152        if ((rv = xbps_transaction_fetch(xhp, iter)) != 0) {
 
  154                    "%s\n", strerror(rv));
 
  157        if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
 
  165        xbps_fetch_unset_cache_connection();
 
  170        if ((rv = xbps_transaction_internalize(xhp, iter)) < 0) {
 
  172                    "%s\n", strerror(-rv));
 
  180        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FILES, 0, NULL, NULL);
 
  181        if ((rv = xbps_transaction_files(xhp, iter)) != 0) {
 
  183                    "%s\n", strerror(rv));
 
  191        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL);
 
  199                        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, errno, xhp->
rootdir,
 
  200                            "[trans] failed to create rootdir `%s': %s",
 
  205        if (chdir(xhp->
rootdir) == -1) {
 
  207                xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, rv, xhp->
rootdir,
 
  208                    "[trans] failed to chdir to rootdir `%s': %s",
 
  209                    xhp->
rootdir, strerror(errno));
 
  219        while ((obj = xbps_object_iterator_next(iter)) != NULL) {
 
  220                xbps_dictionary_t dict;
 
  221                xbps_data_t script = NULL;
 
  222                const char *pkgdb_pkgver;
 
  224                xbps_dictionary_get_cstring_nocopy(obj, 
"pkgver", &pkgver);
 
  225                xbps_dictionary_get_cstring_nocopy(obj, 
"pkgname", &pkgname);
 
  228                if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
 
  230                            "%s: %d\n", __func__, pkgver, ttype);
 
  237                            pkgname, strerror(rv));
 
  241                script = xbps_dictionary_get(pkgdb_pkgd, 
"remove-script");
 
  245                xbps_dictionary_get_cstring_nocopy(pkgdb_pkgd, 
"pkgver", &pkgdb_pkgver);
 
  246                assert(pkgdb_pkgver);
 
  248                update = ttype == XBPS_TRANS_UPDATE;
 
  252                        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
 
  253                            "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
 
  254                            pkgver, strerror(rv));
 
  260                dict = xbps_dictionary_create();
 
  262                        rv = errno ? errno : ENOMEM;
 
  265                if (!xbps_dictionary_set_cstring(dict, 
"pkgver", pkgdb_pkgver)) {
 
  266                        rv = errno ? errno : ENOMEM;
 
  269                if (!xbps_dictionary_set(dict, 
"remove-script", script)) {
 
  270                        rv = errno ? errno : ENOMEM;
 
  273                if (!xbps_array_add(remove_scripts, dict)) {
 
  274                        rv = errno ? errno : ENOMEM;
 
  277                xbps_object_release(dict);
 
  279        xbps_object_iterator_reset(iter);
 
  284        while ((obj = xbps_object_iterator_next(iter)) != NULL) {
 
  285                xbps_dictionary_get_cstring_nocopy(obj, 
"pkgver", &pkgver);
 
  287                if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
 
  289                            "%s: %d\n", __func__, pkgver, ttype);
 
  294                        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
 
  295                            "%s: [trans] INSTALL script failed to execute pre ACTION: %s",
 
  296                            pkgver, strerror(rv));
 
  300        xbps_object_iterator_reset(iter);
 
  303        while ((obj = xbps_object_iterator_next(iter)) != NULL) {
 
  304                xbps_dictionary_get_cstring_nocopy(obj, 
"pkgver", &pkgver);
 
  307                if (ttype == XBPS_TRANS_REMOVE) {
 
  312                        xbps_dictionary_get_bool(obj, 
"remove-and-update", &update);
 
  313                        rv = xbps_remove_pkg(xhp, pkgver, update);
 
  316                                    "remove %s: %s\n", pkgver, strerror(rv));
 
  321                } 
else if (ttype == XBPS_TRANS_UPDATE) {
 
  326                        xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0, pkgver, NULL);
 
  327                        rv = xbps_remove_pkg(xhp, pkgver, 
true);
 
  329                                xbps_set_cb_state(xhp,
 
  330                                    XBPS_STATE_UPDATE_FAIL,
 
  332                                    "%s: [trans] failed to update " 
  333                                    "package `%s'", pkgver,
 
  337                } 
else if (ttype == XBPS_TRANS_CONFIGURE) {
 
  342                } 
else if (ttype == XBPS_TRANS_HOLD) {
 
  349                        xbps_set_cb_state(xhp, XBPS_STATE_INSTALL, 0,
 
  355                if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0) {
 
  357                            "%s: %s\n", pkgver, strerror(rv));
 
  363                if ((rv = xbps_register_pkg(xhp, obj)) != 0) {
 
  365                            "%s: %s\n", pkgver, strerror(rv));
 
  370        if (!xbps_dictionary_get(xhp->
transd, 
"total-update-pkgs") &&
 
  371            !xbps_dictionary_get(xhp->
transd, 
"total-install-pkgs"))
 
  378        } 
else if (xhp->
flags & XBPS_FLAG_UNPACK_ONLY) {
 
  382        xbps_object_iterator_reset(iter);
 
  390        rv = run_post_remove_scripts(xhp, remove_scripts);
 
  399        xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
 
  401        while ((obj = xbps_object_iterator_next(iter)) != NULL) {
 
  402                xbps_dictionary_get_cstring_nocopy(obj, 
"pkgver", &pkgver);
 
  404                if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
 
  406                            "%s: %d\n", __func__, pkgver, ttype);
 
  410                if (ttype == XBPS_TRANS_UPDATE)
 
  416                            "%s: %s\n", __func__, pkgver, strerror(rv));
 
  424                        xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
 
  427                        xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
 
  433        xbps_object_release(remove_scripts);
 
  434        xbps_object_iterator_release(iter);