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;
112 bool update, replaced;
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);
236 xbps_dictionary_get_bool(obj,
"replaced", &replaced);
242 pkgname, strerror(rv));
246 script = xbps_dictionary_get(pkgdb_pkgd,
"remove-script");
250 xbps_dictionary_get_cstring_nocopy(pkgdb_pkgd,
"pkgver", &pkgdb_pkgver);
251 assert(pkgdb_pkgver);
253 update = ttype == XBPS_TRANS_UPDATE;
257 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
258 "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
259 pkgver, strerror(rv));
265 dict = xbps_dictionary_create();
267 rv = errno ? errno : ENOMEM;
270 if (!xbps_dictionary_set_cstring(dict,
"pkgver", pkgdb_pkgver)) {
271 rv = errno ? errno : ENOMEM;
274 if (!xbps_dictionary_set(dict,
"remove-script", script)) {
275 rv = errno ? errno : ENOMEM;
278 if (!xbps_array_add(remove_scripts, dict)) {
279 rv = errno ? errno : ENOMEM;
282 xbps_object_release(dict);
284 xbps_object_iterator_reset(iter);
289 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
290 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
292 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
294 "%s: %d\n", __func__, pkgver, ttype);
299 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
300 "%s: [trans] INSTALL script failed to execute pre ACTION: %s",
301 pkgver, strerror(rv));
305 xbps_object_iterator_reset(iter);
308 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
309 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
310 xbps_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
313 if (ttype == XBPS_TRANS_REMOVE) {
318 xbps_dictionary_get_bool(obj,
"remove-and-update", &update);
320 xbps_dictionary_get_bool(obj,
"replaced", &replaced);
324 rv = xbps_remove_pkg(xhp, pkgver, update);
327 "remove %s: %s\n", pkgver, strerror(rv));
332 }
else if (ttype == XBPS_TRANS_UPDATE) {
337 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0, pkgver, NULL);
338 rv = xbps_remove_pkg(xhp, pkgver,
true);
340 xbps_set_cb_state(xhp,
341 XBPS_STATE_UPDATE_FAIL,
343 "%s: [trans] failed to update "
344 "package `%s'", pkgver,
348 }
else if (ttype == XBPS_TRANS_CONFIGURE) {
353 }
else if (ttype == XBPS_TRANS_HOLD) {
360 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL, 0,
366 if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0) {
368 "%s: %s\n", pkgver, strerror(rv));
374 if ((rv = xbps_register_pkg(xhp, obj)) != 0) {
376 "%s: %s\n", pkgver, strerror(rv));
381 if (!xbps_dictionary_get(xhp->
transd,
"total-update-pkgs") &&
382 !xbps_dictionary_get(xhp->
transd,
"total-install-pkgs"))
389 }
else if (xhp->
flags & XBPS_FLAG_UNPACK_ONLY) {
393 xbps_object_iterator_reset(iter);
401 rv = run_post_remove_scripts(xhp, remove_scripts);
410 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
412 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
413 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
415 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
417 "%s: %d\n", __func__, pkgver, ttype);
421 if (ttype == XBPS_TRANS_UPDATE)
427 "%s: %s\n", __func__, pkgver, strerror(rv));
435 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
438 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
444 xbps_object_release(remove_scripts);
445 xbps_object_iterator_release(iter);