richardphibel / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
629b27
From 5c97d7f83f56015d6a37934cee4e55ed8d747890 Mon Sep 17 00:00:00 2001
629b27
From: chantra <chantr4@gmail.com>
629b27
Date: Tue, 8 Feb 2022 16:57:25 -0800
629b27
Subject: [PATCH 13/30] [plugin] add `plugin_fsm_file_install_func` plugin hook
629b27
629b27
This hook is to be called when installing individual files from the RPM.
629b27
---
629b27
 lib/rpmplugin.h  |  5 +++++
629b27
 lib/rpmplugins.c | 37 +++++++++++++++++++++++++++++++++++++
629b27
 lib/rpmplugins.h | 15 +++++++++++++++
629b27
 3 files changed, 57 insertions(+)
629b27
629b27
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
629b27
index fd81aec8d..877db81f3 100644
629b27
--- a/lib/rpmplugin.h
629b27
+++ b/lib/rpmplugin.h
629b27
@@ -60,6 +60,10 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin plugin, rpmfi fi,
629b27
 					      const char* path,
629b27
 					      const char *dest,
629b27
 					      mode_t file_mode, rpmFsmOp op);
629b27
+typedef rpmRC (*plugin_fsm_file_install_func)(rpmPlugin plugin, rpmfi fi,
629b27
+					      const char* path,
629b27
+					      mode_t file_mode, rpmFsmOp op);
629b27
+
629b27
 
629b27
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
629b27
 struct rpmPluginHooks_s {
629b27
@@ -80,6 +84,7 @@ struct rpmPluginHooks_s {
629b27
     plugin_fsm_file_pre_func		fsm_file_pre;
629b27
     plugin_fsm_file_post_func		fsm_file_post;
629b27
     plugin_fsm_file_prepare_func	fsm_file_prepare;
629b27
+    plugin_fsm_file_install_func	fsm_file_install;
629b27
 };
629b27
 
629b27
 #ifdef __cplusplus
629b27
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
629b27
index 3da3097af..850a025a0 100644
629b27
--- a/lib/rpmplugins.c
629b27
+++ b/lib/rpmplugins.c
629b27
@@ -421,3 +421,40 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
629b27
 
629b27
     return rc;
629b27
 }
629b27
+
629b27
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
629b27
+				   const char *path, mode_t file_mode,
629b27
+				   rpmFsmOp op)
629b27
+{
629b27
+    plugin_fsm_file_install_func hookFunc;
629b27
+    int i;
629b27
+    rpmRC rc = RPMRC_OK;
629b27
+    rpmRC hook_rc;
629b27
+
629b27
+    for (i = 0; i < plugins->count; i++) {
629b27
+	rpmPlugin plugin = plugins->plugins[i];
629b27
+	RPMPLUGINS_SET_HOOK_FUNC(fsm_file_install);
629b27
+	if (hookFunc) {
629b27
+	    hook_rc = hookFunc(plugin, fi, path, file_mode, op);
629b27
+	    if (hook_rc == RPMRC_FAIL) {
629b27
+		rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_install failed\n", plugin->name);
629b27
+		rc = RPMRC_FAIL;
629b27
+	    } else if (hook_rc == RPMRC_PLUGIN_CONTENTS && rc != RPMRC_FAIL) {
629b27
+		if (rc == RPMRC_PLUGIN_CONTENTS) {
629b27
+		    /* Another plugin already said it'd handle contents. It's
629b27
+		     * undefined how these would combine, so treat this as a
629b27
+		     * failure condition.
629b27
+		    */
629b27
+		    rc = RPMRC_FAIL;
629b27
+		} else {
629b27
+		    /* Plugin will handle content */
629b27
+		    rc = RPMRC_PLUGIN_CONTENTS;
629b27
+		}
629b27
+	    }
629b27
+	}
629b27
+    }
629b27
+
629b27
+    return rc;
629b27
+}
629b27
+
629b27
+
629b27
diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
629b27
index 39762c376..5365cf698 100644
629b27
--- a/lib/rpmplugins.h
629b27
+++ b/lib/rpmplugins.h
629b27
@@ -167,6 +167,21 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
629b27
                                    const char *path, const char *dest,
629b27
                                    mode_t mode, rpmFsmOp op);
629b27
 
629b27
+/** \ingroup rpmplugins
629b27
+ * Call the fsm file install plugin hook
629b27
+ * @param plugins	plugins structure
629b27
+ * @param fi		file info iterator (or NULL)
629b27
+ * @param path		file object path
629b27
+ * @param file_mode	file object mode
629b27
+ * @param op		file operation + associated flags
629b27
+ * @return		RPMRC_OK on success, RPMRC_FAIL otherwise
629b27
+ */
629b27
+RPM_GNUC_INTERNAL
629b27
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
629b27
+				   const char* path, mode_t file_mode,
629b27
+				   rpmFsmOp op);
629b27
+
629b27
+
629b27
 #ifdef __cplusplus
629b27
 }
629b27
 #endif
629b27
-- 
629b27
2.35.1
629b27