Introduce fsm_pre and fsm_post hooks, which are invoked
before and after the package files are installed.

Signed-off-by: Stefan Berger <stef...@linux.vnet.ibm.com>
---
 lib/psm.c        |  6 +++++-
 lib/rpmplugin.h  |  6 ++++++
 lib/rpmplugins.c | 35 +++++++++++++++++++++++++++++++++++
 lib/rpmplugins.h | 19 +++++++++++++++++++
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/lib/psm.c b/lib/psm.c
index 341441b..ddd38d1 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -586,11 +586,13 @@ static rpmRC rpmpsmUnpack(rpmpsm psm)
     rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, 0);
 
     if (!(rpmtsFlags(psm->ts) & RPMTRANS_FLAG_JUSTDB)) {
-       if (rpmfilesFC(psm->files) > 0) {
+       fsmrc = rpmpluginsCallFsmPre(rpmtsPlugins(psm->ts), psm->te);
+       if (!fsmrc && rpmfilesFC(psm->files) > 0) {
            fsmrc = rpmPackageFilesInstall(psm->ts, psm->te, psm->files,
                                   psm, &failedFile);
            saved_errno = errno;
        }
+       rpmpluginsCallFsmPost(rpmtsPlugins(psm->ts), psm->te, fsmrc);
     }
 
     /* XXX make sure progress reaches 100% */
@@ -627,10 +629,12 @@ static rpmRC rpmpsmRemove(rpmpsm psm)
 
     /* XXX should't we log errors from here? */
     if (!(rpmtsFlags(psm->ts) & RPMTRANS_FLAG_JUSTDB)) {
+       fsmrc = rpmpluginsCallFsmPre(rpmtsPlugins(psm->ts), psm->te);
        if (rpmfilesFC(psm->files) > 0) {
            fsmrc = rpmPackageFilesRemove(psm->ts, psm->te, psm->files,
                                          psm, &failedFile);
        }
+       rpmpluginsCallFsmPost(rpmtsPlugins(psm->ts), psm->te, fsmrc);
     }
     /* XXX make sure progress reaches 100% */
     rpmpsmNotify(psm, RPMCALLBACK_UNINST_PROGRESS, psm->total);
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
index fd81aec..b6f230c 100644
--- a/lib/rpmplugin.h
+++ b/lib/rpmplugin.h
@@ -41,6 +41,8 @@ typedef rpmRC (*plugin_init_func)(rpmPlugin plugin, rpmts ts);
 typedef void (*plugin_cleanup_func)(rpmPlugin plugin);
 typedef rpmRC (*plugin_tsm_pre_func)(rpmPlugin plugin, rpmts ts);
 typedef rpmRC (*plugin_tsm_post_func)(rpmPlugin plugin, rpmts ts, int res);
+typedef rpmRC (*plugin_fsm_pre_func)(rpmPlugin plugin, rpmte te);
+typedef rpmRC (*plugin_fsm_post_func)(rpmPlugin plugin, rpmte te, int res);
 typedef rpmRC (*plugin_psm_pre_func)(rpmPlugin plugin, rpmte te);
 typedef rpmRC (*plugin_psm_post_func)(rpmPlugin plugin, rpmte te, int res);
 typedef rpmRC (*plugin_scriptlet_pre_func)(rpmPlugin plugin,
@@ -60,6 +62,8 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin 
plugin, rpmfi fi,
                                              const char* path,
                                              const char *dest,
                                              mode_t file_mode, rpmFsmOp op);
+typedef rpmRC (*plugin_fsm_pre_func)(rpmPlugin plugin, rpmte te);
+typedef rpmRC (*plugin_fsm_post_func)(rpmPlugin plugin, rpmte te, int res);
 
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
 struct rpmPluginHooks_s {
@@ -80,6 +84,8 @@ struct rpmPluginHooks_s {
     plugin_fsm_file_pre_func           fsm_file_pre;
     plugin_fsm_file_post_func          fsm_file_post;
     plugin_fsm_file_prepare_func       fsm_file_prepare;
+    plugin_fsm_pre_func                        fsm_pre;
+    plugin_fsm_post_func               fsm_post;
 };
 
 #ifdef __cplusplus
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
index 97e5d30..98cd5ca 100644
--- a/lib/rpmplugins.c
+++ b/lib/rpmplugins.c
@@ -401,3 +401,38 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, 
rpmfi fi,
 
     return rc;
 }
+
+rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te)
+{
+    plugin_fsm_pre_func hookFunc;
+    int i;
+    rpmRC rc = RPMRC_OK;
+
+    for (i = 0; i < plugins->count; i++) {
+       rpmPlugin plugin = plugins->plugins[i];
+       RPMPLUGINS_SET_HOOK_FUNC(fsm_pre);
+       if (hookFunc && hookFunc(plugin, te) == RPMRC_FAIL) {
+           rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_pre failed\n", 
plugin->name);
+           rc = RPMRC_FAIL;
+       }
+    }
+
+    return rc;
+}
+
+rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int res)
+{
+    plugin_fsm_post_func hookFunc;
+    int i;
+    rpmRC rc = RPMRC_OK;
+
+    for (i = 0; i < plugins->count; i++) {
+       rpmPlugin plugin = plugins->plugins[i];
+       RPMPLUGINS_SET_HOOK_FUNC(fsm_post);
+       if (hookFunc && hookFunc(plugin, te, res) == RPMRC_FAIL) {
+           rpmlog(RPMLOG_WARNING, "Plugin %s: hook fsm_post failed\n", 
plugin->name);
+       }
+    }
+
+    return rc;
+}
diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
index 39762c3..3702526 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -167,6 +167,25 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, 
rpmfi fi,
                                    const char *path, const char *dest,
                                    mode_t mode, rpmFsmOp op);
 
+/** \ingroup rpmplugins
+ * Call the fsm pre plugin hook.
+ * @param plugins      plugins structure
+ * @param te           processed transaction element
+ * @return             RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te);
+
+/** \ingroup rpmplugins
+ * Call the fsm post plugin hook.
+ * @param plugins      plugins structure
+ * @param te           processed transaction element
+ * @param res          fsm result code
+ * @return             RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int rc);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.5.5

_______________________________________________
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint

Reply via email to