Blob Blame History Raw
From 048db395b6de8544dc88231f0afebee8570daee6 Mon Sep 17 00:00:00 2001
From: chantra <chantr4@gmail.com>
Date: Tue, 8 Feb 2022 18:21:33 -0800
Subject: [PATCH 18/30] [plugin] add `rpmpluginsCallFsmFileArchiveReader`

This allows plugins to provide a custom `rpmfi` to
`rpmPackageFilesInstall` function in fsm.c. It enables supporting
transcoded files such as with reflink plugin.
---
 lib/rpmplugin.h  |  4 ++++
 lib/rpmplugins.c | 34 ++++++++++++++++++++++++++++++++++
 lib/rpmplugins.h |  4 +++-
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
index 877db81f3..6dbbcff35 100644
--- a/lib/rpmplugin.h
+++ b/lib/rpmplugin.h
@@ -63,6 +63,9 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin plugin, rpmfi fi,
 typedef rpmRC (*plugin_fsm_file_install_func)(rpmPlugin plugin, rpmfi fi,
 					      const char* path,
 					      mode_t file_mode, rpmFsmOp op);
+typedef rpmRC (*plugin_fsm_file_archive_reader_func)(rpmPlugin plugin,
+						     FD_t payload,
+						     rpmfiles files, rpmfi *fi);
 
 
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
@@ -85,6 +88,7 @@ struct rpmPluginHooks_s {
     plugin_fsm_file_post_func		fsm_file_post;
     plugin_fsm_file_prepare_func	fsm_file_prepare;
     plugin_fsm_file_install_func	fsm_file_install;
+    plugin_fsm_file_archive_reader_func	fsm_file_archive_reader;
 };
 
 #ifdef __cplusplus
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
index 850a025a0..901af1ac5 100644
--- a/lib/rpmplugins.c
+++ b/lib/rpmplugins.c
@@ -471,4 +471,38 @@ rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
     return rc;
 }
 
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
+				   rpmfiles files, rpmfi *fi)
+{
+    plugin_fsm_file_archive_reader_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_archive_reader);
+	if (hookFunc) {
+	    hook_rc = hookFunc(plugin, payload, files, fi);
+	    if (hook_rc == RPMRC_FAIL) {
+		rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_archive_reader 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 5365cf698..88807c53c 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -182,7 +182,9 @@ rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
 				   const char* path, mode_t file_mode,
 				   rpmFsmOp op);
 
-
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
+					 rpmfiles files, rpmfi *fi);
 #ifdef __cplusplus
 }
 #endif
-- 
2.35.1