lib: run pre-remove and pre-install scripts before unpacking

This commit is contained in:
Duncan Overbruck 2021-06-24 17:33:26 +02:00
parent c94648630c
commit 02367e3c00
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35
4 changed files with 57 additions and 23 deletions

View File

@ -165,6 +165,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
printf("%s\n", xscd->desc);
break;
/* errors */
case XBPS_STATE_TRANS_FAIL:
case XBPS_STATE_UNPACK_FAIL:
case XBPS_STATE_UPDATE_FAIL:
case XBPS_STATE_CONFIGURE_FAIL:

View File

@ -153,18 +153,7 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
/* If package was "half-removed", remove it fully. */
if (state == XBPS_PKG_STATE_HALF_REMOVED)
goto purge;
/*
* Run the pre remove action and show pre-remove message if exists.
*/
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "pre", update);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgver,
"%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s",
pkgver, strerror(rv));
goto out;
}
/* show remove-msg if exists */
if ((rv = xbps_cb_message(xhp, pkgd, "remove-msg")) != 0)
goto out;

View File

@ -198,16 +198,6 @@ unpack_archive(struct xbps_handle *xhp,
*/
pkg_filesd = xbps_pkgdb_get_pkg_files(xhp, pkgname);
/*
* Execute INSTALL "pre" ACTION before unpacking files.
*/
rv = xbps_pkg_exec_script(xhp, pkg_repod, "install-script", "pre", update);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, rv, pkgver,
"%s: [unpack] INSTALL script failed to execute pre ACTION: %s",
pkgver, strerror(rv));
goto out;
}
/*
* Unpack all files on archive now.
*/

View File

@ -59,10 +59,11 @@
int
xbps_transaction_commit(struct xbps_handle *xhp)
{
xbps_dictionary_t pkgdb_pkgd;
xbps_object_t obj;
xbps_object_iterator_t iter;
xbps_trans_type_t ttype;
const char *pkgver = NULL;
const char *pkgver = NULL, *pkgname = NULL;
int rv = 0;
bool update;
@ -155,6 +156,59 @@ xbps_transaction_commit(struct xbps_handle *xhp)
xhp->rootdir, strerror(errno));
goto out;
}
/*
* Run all pre-remove scripts.
*/
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
ttype = xbps_transaction_pkg_type(obj);
if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
xbps_dbg_printf(xhp, "%s: skipping pre-remove script for "
"%s: %d\n", __func__, pkgver, ttype);
continue;
}
if ((pkgdb_pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
rv = errno;
xbps_dbg_printf(xhp, "[trans] cannot find %s in pkgdb: %s\n",
pkgver, strerror(rv));
goto out;
}
update = ttype == XBPS_TRANS_UPDATE;
rv = xbps_pkg_exec_script(xhp, pkgdb_pkgd, "remove-script", "pre", update);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
"%s: [trans] REMOVE script failed to execute pre ACTION: %s",
pkgver, strerror(rv));
goto out;
}
}
xbps_object_iterator_reset(iter);
/*
* Run all pre-install scripts.
*/
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
ttype = xbps_transaction_pkg_type(obj);
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
xbps_dbg_printf(xhp, "%s: skipping pre-install script for "
"%s: %d\n", __func__, pkgver, ttype);
continue;
}
rv = xbps_pkg_exec_script(xhp, obj, "install-script", "pre", ttype == XBPS_TRANS_UPDATE);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_FAIL, rv, pkgver,
"%s: [trans] INSTALL script failed to execute pre ACTION: %s",
pkgver, strerror(rv));
goto out;
}
}
xbps_object_iterator_reset(iter);
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);