104 xbps_array_t remove_scripts;
105 xbps_dictionary_t pkgdb_pkgd;
107 xbps_object_iterator_t iter;
109 const char *pkgver = NULL, *pkgname = NULL;
112 setlocale(LC_ALL,
"");
119 remove_scripts = xbps_array_create();
120 if (remove_scripts == NULL)
121 return errno ? errno : ENOMEM;
123 assert(xbps_object_type(xhp->
transd) == XBPS_TYPE_DICTIONARY);
128 if (errno != EEXIST) {
129 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
131 "[trans] cannot create cachedir `%s': %s",
137 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL,
139 "[trans] failed to change dir to cachedir `%s': %s",
150 if ((rv = xbps_transaction_fetch(xhp, iter)) != 0) {
152 "%s\n", strerror(rv));
155 if (xhp->
flags & XBPS_FLAG_DOWNLOAD_ONLY) {
163 xbps_fetch_unset_cache_connection();
168 if ((rv = xbps_transaction_internalize(xhp, iter)) < 0) {
170 "%s\n", strerror(-rv));
178 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FILES, 0, NULL, NULL);
179 if ((rv = xbps_transaction_files(xhp, iter)) != 0) {
181 "%s\n", strerror(rv));
189 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL);
197 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, errno, xhp->
rootdir,
198 "[trans] failed to create rootdir `%s': %s",
203 if (chdir(xhp->
rootdir) == -1) {
205 xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, rv, xhp->
rootdir,
206 "[trans] failed to chdir to rootdir `%s': %s",
207 xhp->
rootdir, strerror(errno));
217 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
218 xbps_dictionary_t dict;
219 xbps_data_t script = NULL;
220 const char *pkgdb_pkgver;
223 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
224 xbps_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
227 if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
229 "%s: %d\n", __func__, pkgver, ttype);
234 bool replaced =
false;
235 xbps_dictionary_get_bool(obj,
"replaced", &replaced);
241 pkgname, strerror(rv));
245 script = xbps_dictionary_get(pkgdb_pkgd,
"remove-script");
249 xbps_dictionary_get_cstring_nocopy(pkgdb_pkgd,
"pkgver", &pkgdb_pkgver);
250 assert(pkgdb_pkgver);
252 update = ttype == XBPS_TRANS_UPDATE;
256 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
257 "%s: [trans] REMOVE script failed to execute pre ACTION: %s",
258 pkgver, strerror(rv));
264 dict = xbps_dictionary_create();
266 rv = errno ? errno : ENOMEM;
269 if (!xbps_dictionary_set_cstring(dict,
"pkgver", pkgdb_pkgver)) {
270 rv = errno ? errno : ENOMEM;
273 if (!xbps_dictionary_set(dict,
"remove-script", script)) {
274 rv = errno ? errno : ENOMEM;
277 if (!xbps_array_add(remove_scripts, dict)) {
278 rv = errno ? errno : ENOMEM;
281 xbps_object_release(dict);
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) {
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);
309 xbps_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
312 if (ttype == XBPS_TRANS_REMOVE) {
313 bool replaced =
false;
318 xbps_dictionary_get_bool(obj,
"remove-and-update", &update);
319 xbps_dictionary_get_bool(obj,
"replaced", &replaced);
323 rv = xbps_remove_pkg(xhp, pkgver, update);
326 "remove %s: %s\n", pkgver, strerror(rv));
331 }
else if (ttype == XBPS_TRANS_UPDATE) {
336 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0, pkgver, NULL);
337 rv = xbps_remove_pkg(xhp, pkgver,
true);
339 xbps_set_cb_state(xhp,
340 XBPS_STATE_UPDATE_FAIL,
342 "%s: [trans] failed to update "
343 "package `%s'", pkgver,
347 }
else if (ttype == XBPS_TRANS_CONFIGURE) {
352 }
else if (ttype == XBPS_TRANS_HOLD) {
359 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL, 0,
365 if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0) {
367 "%s: %s\n", pkgver, strerror(rv));
373 if ((rv = xbps_register_pkg(xhp, obj)) != 0) {
375 "%s: %s\n", pkgver, strerror(rv));
380 if (!xbps_dictionary_get(xhp->
transd,
"total-update-pkgs") &&
381 !xbps_dictionary_get(xhp->
transd,
"total-install-pkgs"))
388 }
else if (xhp->
flags & XBPS_FLAG_UNPACK_ONLY) {
392 xbps_object_iterator_reset(iter);
400 rv = run_post_remove_scripts(xhp, remove_scripts);
409 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
411 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
414 xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
416 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
418 "%s: %d\n", __func__, pkgver, ttype);
421 update = ttype == XBPS_TRANS_UPDATE;
426 "%s: %s\n", __func__, pkgver, strerror(rv));
434 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
437 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
443 xbps_object_release(remove_scripts);
444 xbps_object_iterator_release(iter);