Blob Blame History Raw
From 5c97d7f83f56015d6a37934cee4e55ed8d747890 Mon Sep 17 00:00:00 2001
From: chantra <chantr4@gmail.com>
Date: Tue, 8 Feb 2022 16:57:25 -0800
Subject: [PATCH 13/30] [plugin] add `plugin_fsm_file_install_func` plugin hook

This hook is to be called when installing individual files from the RPM.
---
 lib/rpmplugin.h  |  5 +++++
 lib/rpmplugins.c | 37 +++++++++++++++++++++++++++++++++++++
 lib/rpmplugins.h | 15 +++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
index fd81aec8d..877db81f3 100644
--- a/lib/rpmplugin.h
+++ b/lib/rpmplugin.h
@@ -60,6 +60,10 @@ 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_file_install_func)(rpmPlugin plugin, rpmfi fi,
+					      const char* path,
+					      mode_t file_mode, rpmFsmOp op);
+
 
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
 struct rpmPluginHooks_s {
@@ -80,6 +84,7 @@ 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_file_install_func	fsm_file_install;
 };
 
 #ifdef __cplusplus
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
index 3da3097af..850a025a0 100644
--- a/lib/rpmplugins.c
+++ b/lib/rpmplugins.c
@@ -421,3 +421,40 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
 
     return rc;
 }
+
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
+				   const char *path, mode_t file_mode,
+				   rpmFsmOp op)
+{
+    plugin_fsm_file_install_func hookFunc;
+    int i;
+    rpmRC rc = RPMRC_OK;
+    rpmRC hook_rc;
+
+    for (i = 0; i < plugins->count; i++) {
+	rpmPlugin plugin = plugins->plugins[i];
+	RPMPLUGINS_SET_HOOK_FUNC(fsm_file_install);
+	if (hookFunc) {
+	    hook_rc = hookFunc(plugin, fi, path, file_mode, op);
+	    if (hook_rc == RPMRC_FAIL) {
+		rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_install failed\n", plugin->name);
+		rc = RPMRC_FAIL;
+	    } else if (hook_rc == RPMRC_PLUGIN_CONTENTS && rc != RPMRC_FAIL) {
+		if (rc == RPMRC_PLUGIN_CONTENTS) {
+		    /* Another plugin already said it'd handle contents. It's
+		     * undefined how these would combine, so treat this as a
+		     * failure condition.
+		    */
+		    rc = RPMRC_FAIL;
+		} else {
+		    /* Plugin will handle content */
+		    rc = RPMRC_PLUGIN_CONTENTS;
+		}
+	    }
+	}
+    }
+
+    return rc;
+}
+
+
diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
index 39762c376..5365cf698 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -167,6 +167,21 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
                                    const char *path, const char *dest,
                                    mode_t mode, rpmFsmOp op);
 
+/** \ingroup rpmplugins
+ * Call the fsm file install plugin hook
+ * @param plugins	plugins structure
+ * @param fi		file info iterator (or NULL)
+ * @param path		file object path
+ * @param file_mode	file object mode
+ * @param op		file operation + associated flags
+ * @return		RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
+				   const char* path, mode_t file_mode,
+				   rpmFsmOp op);
+
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.35.1