36#include "xbps_api_impl.h"
60run_post_remove_scripts(
struct xbps_handle *xhp, xbps_array_t remove_scripts)
64 for (
unsigned int i = 0; i < xbps_array_count(remove_scripts); i++) {
65 xbps_dictionary_t dict;
67 xbps_data_t script = NULL;
68 const char *pkgver = NULL;
72 dict = xbps_array_get(remove_scripts, i);
75 xbps_dictionary_get_cstring_nocopy(dict,
"pkgver", &pkgver);
78 xbps_dictionary_get_bool(dict,
"update", &update);
80 script = xbps_dictionary_get(dict,
"remove-script");
83 buf = xbps_data_data_nocopy(script);
84 buflen = xbps_data_size(script);
87 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
88 "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
89 pkgver, strerror(rv));
94 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
95 "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
96 pkgver, strerror(rv));
108 xbps_array_t remove_scripts;
109 xbps_dictionary_t pkgdb_pkgd;
111 xbps_object_iterator_t iter;
113 const char *pkgver = NULL, *pkgname = NULL;
117 setlocale(LC_ALL,
"");
124 remove_scripts = xbps_array_create();
125 if (remove_scripts == NULL)
126 return errno ? errno : ENOMEM;
128 assert(xbps_object_type(xhp->
transd) == XBPS_TYPE_DICTIONARY);
133 if (errno != EEXIST) {
134 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
136 "[trans] cannot create cachedir `%s': %s",
142 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
144 "[trans] failed to change dir to cachedir `%s': %s",
155 if ((rv = xbps_transaction_fetch(xhp, iter)) != 0) {
156 xbps_dbg_printf(
"[trans] failed to fetch and verify binpkgs: "
157 "%s\n", strerror(rv));
160 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
168 xbps_fetch_unset_cache_connection();
173 if ((rv = xbps_transaction_internalize(xhp, iter)) < 0) {
174 xbps_dbg_printf(
"[trans] failed to internalize transaction binpkgs: "
175 "%s\n", strerror(-rv));
183 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FILES, 0, NULL, NULL);
184 if ((rv = xbps_transaction_files(xhp, iter)) != 0) {
185 xbps_dbg_printf(
"[trans] failed to verify transaction files: "
186 "%s\n", strerror(rv));
194 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL);
202 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, errno, xhp->
rootdir,
203 "[trans] failed to create rootdir `%s': %s",
208 if (chdir(xhp->
rootdir) == -1) {
210 xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, rv, xhp->
rootdir,
211 "[trans] failed to chdir to rootdir `%s': %s",
212 xhp->
rootdir, strerror(errno));
222 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
223 xbps_dictionary_t dict;
224 xbps_data_t script = NULL;
225 const char *pkgdb_pkgver;
227 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
228 xbps_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
231 if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
232 xbps_dbg_printf(
"%s: skipping pre-remove script for "
233 "%s: %d\n", __func__, pkgver, ttype);
239 xbps_dbg_printf(
"[trans] cannot find %s in pkgdb: %s\n",
240 pkgname, strerror(rv));
244 script = xbps_dictionary_get(pkgdb_pkgd,
"remove-script");
248 xbps_dictionary_get_cstring_nocopy(pkgdb_pkgd,
"pkgver", &pkgdb_pkgver);
249 assert(pkgdb_pkgver);
251 update = ttype == XBPS_TRANS_UPDATE;
253 dict = xbps_dictionary_create();
255 rv = errno ? errno : ENOMEM;
258 if (!xbps_dictionary_set_cstring(dict,
"pkgver", pkgdb_pkgver)) {
259 rv = errno ? errno : ENOMEM;
262 if (!xbps_dictionary_set_bool(dict,
"update", update)) {
263 rv = errno ? errno : ENOMEM;
266 if (!xbps_dictionary_set(dict,
"remove-script", script)) {
267 rv = errno ? errno : ENOMEM;
270 if (!xbps_array_add(remove_scripts, dict)) {
271 rv = errno ? errno : ENOMEM;
274 xbps_object_release(dict);
277 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
278 "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
279 pkgver, strerror(rv));
283 xbps_object_iterator_reset(iter);
288 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
289 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
291 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
292 xbps_dbg_printf(
"%s: skipping pre-install script for "
293 "%s: %d\n", __func__, pkgver, ttype);
298 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
299 "%s: [trans] INSTALL script failed to execute pre ACTION: %s",
300 pkgver, strerror(rv));
304 xbps_object_iterator_reset(iter);
307 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
308 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
311 if (ttype == XBPS_TRANS_REMOVE) {
316 xbps_dictionary_get_bool(obj,
"remove-and-update", &update);
317 rv = xbps_remove_pkg(xhp, pkgver, update);
319 xbps_dbg_printf(
"[trans] failed to "
320 "remove %s: %s\n", pkgver, strerror(rv));
325 }
else if (ttype == XBPS_TRANS_UPDATE) {
330 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0, pkgver, NULL);
331 rv = xbps_remove_pkg(xhp, pkgver,
true);
333 xbps_set_cb_state(xhp,
334 XBPS_STATE_UPDATE_FAIL,
336 "%s: [trans] failed to update "
337 "package `%s'", pkgver,
341 }
else if (ttype == XBPS_TRANS_CONFIGURE) {
346 }
else if (ttype == XBPS_TRANS_HOLD) {
353 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL, 0,
359 if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0) {
360 xbps_dbg_printf(
"[trans] failed to unpack "
361 "%s: %s\n", pkgver, strerror(rv));
367 if ((rv = xbps_register_pkg(xhp, obj)) != 0) {
368 xbps_dbg_printf(
"[trans] failed to register "
369 "%s: %s\n", pkgver, strerror(rv));
374 if (!xbps_dictionary_get(xhp->
transd,
"total-update-pkgs") &&
375 !xbps_dictionary_get(xhp->
transd,
"total-install-pkgs"))
382 }
else if (xhp->
flags & XBPS_FLAG_UNPACK_ONLY) {
386 xbps_object_iterator_reset(iter);
394 rv = run_post_remove_scripts(xhp, remove_scripts);
403 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
405 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
406 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
408 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
409 xbps_dbg_printf(
"%s: skipping configuration for "
410 "%s: %d\n", __func__, pkgver, ttype);
414 if (ttype == XBPS_TRANS_UPDATE)
419 xbps_dbg_printf(
"%s: configure failed for "
420 "%s: %s\n", __func__, pkgver, strerror(rv));
428 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
431 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
437 xbps_object_release(remove_scripts);
438 xbps_object_iterator_release(iter);
char rootdir[XBPS_MAXPATH]
char cachedir[XBPS_MAXPATH+sizeof(XBPS_CACHE_PATH)]
Generic XBPS structure handler for initialization.
int xbps_pkg_exec_buffer(struct xbps_handle *xhp, const void *blob, const size_t blobsiz, const char *pkgver, const char *action, bool update)
int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
int xbps_pkg_exec_script(struct xbps_handle *xhp, xbps_dictionary_t d, const char *script, const char *action, bool update)
xbps_object_iterator_t xbps_array_iter_from_dict(xbps_dictionary_t dict, const char *key)
int xbps_transaction_commit(struct xbps_handle *xhp)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
int xbps_mkpath(const char *path, mode_t mode)