Implemented support for pre-remove and post-install messages.

Close #44
This commit is contained in:
Juan RP
2014-07-27 11:24:49 +02:00
parent 53d837e69f
commit a28046332f
7 changed files with 145 additions and 6 deletions

View File

@ -256,9 +256,11 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
if (state == XBPS_PKG_STATE_HALF_REMOVED)
goto purge;
/*
* Run the pre remove action.
* Run the pre remove action and show pre-remove message if exists.
*/
if (pkgd) {
xbps_data_t rmsg;
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script",
"pre", update);
if (rv != 0) {
@ -269,6 +271,38 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
pkgver, strerror(rv));
goto out;
}
/* show remove-msg if exists */
rmsg = xbps_dictionary_get(pkgd, "remove-msg");
if (xbps_object_type(rmsg) == XBPS_TYPE_DATA) {
FILE *f;
const void *data;
char *buf;
size_t len;
data = xbps_data_data_nocopy(rmsg);
len = xbps_data_size(rmsg);
if ((f = fmemopen(__UNCONST(data), len, "r")) == NULL) {
rv = errno;
xbps_dbg_printf(xhp, "[remove] %s: fmemopen %s\n", pkgver, strerror(rv));
goto out;
};
buf = malloc(len);
assert(buf);
if (fread(buf, len, 1, f) != len) {
if (ferror(f)) {
rv = errno;
xbps_dbg_printf(xhp, "[remove] %s: fread %s\n", pkgver, strerror(rv));
free(buf);
fclose(f);
goto out;
}
}
/* terminate buffer and notify client to show the pre-remove message */
buf[len] = '\0';
xbps_set_cb_state(xhp, XBPS_STATE_SHOW_REMOVE_MSG, 0, pkgver, "%s", buf);
free(buf);
fclose(f);
}
}
/*
* If updating a package, we just need to execute the current