alexk / rpms / rpm

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