629b27
From 048db395b6de8544dc88231f0afebee8570daee6 Mon Sep 17 00:00:00 2001
629b27
From: chantra <chantr4@gmail.com>
629b27
Date: Tue, 8 Feb 2022 18:21:33 -0800
629b27
Subject: [PATCH 18/30] [plugin] add `rpmpluginsCallFsmFileArchiveReader`
629b27
629b27
This allows plugins to provide a custom `rpmfi` to
629b27
`rpmPackageFilesInstall` function in fsm.c. It enables supporting
629b27
transcoded files such as with reflink plugin.
629b27
---
629b27
 lib/rpmplugin.h  |  4 ++++
629b27
 lib/rpmplugins.c | 34 ++++++++++++++++++++++++++++++++++
629b27
 lib/rpmplugins.h |  4 +++-
629b27
 3 files changed, 41 insertions(+), 1 deletion(-)
629b27
629b27
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
629b27
index 877db81f3..6dbbcff35 100644
629b27
--- a/lib/rpmplugin.h
629b27
+++ b/lib/rpmplugin.h
629b27
@@ -63,6 +63,9 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin plugin, rpmfi fi,
629b27
 typedef rpmRC (*plugin_fsm_file_install_func)(rpmPlugin plugin, rpmfi fi,
629b27
 					      const char* path,
629b27
 					      mode_t file_mode, rpmFsmOp op);
629b27
+typedef rpmRC (*plugin_fsm_file_archive_reader_func)(rpmPlugin plugin,
629b27
+						     FD_t payload,
629b27
+						     rpmfiles files, rpmfi *fi);
629b27
 
629b27
 
629b27
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
629b27
@@ -85,6 +88,7 @@ struct rpmPluginHooks_s {
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
+    plugin_fsm_file_archive_reader_func	fsm_file_archive_reader;
629b27
 };
629b27
 
629b27
 #ifdef __cplusplus
629b27
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
629b27
index 850a025a0..901af1ac5 100644
629b27
--- a/lib/rpmplugins.c
629b27
+++ b/lib/rpmplugins.c
629b27
@@ -457,4 +457,38 @@ rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
629b27
     return rc;
629b27
 }
629b27
 
629b27
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
629b27
+				   rpmfiles files, rpmfi *fi)
629b27
+{
629b27
+    plugin_fsm_file_archive_reader_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_archive_reader);
629b27
+	if (hookFunc) {
629b27
+	    hook_rc = hookFunc(plugin, payload, files, fi);
629b27
+	    if (hook_rc == RPMRC_FAIL) {
629b27
+		rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_archive_reader 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 5365cf698..88807c53c 100644
629b27
--- a/lib/rpmplugins.h
629b27
+++ b/lib/rpmplugins.h
629b27
@@ -181,7 +181,9 @@ rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
629b27
 				   const char* path, mode_t file_mode,
629b27
 				   rpmFsmOp op);
629b27
 
629b27
-
629b27
+RPM_GNUC_INTERNAL
629b27
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
629b27
+					 rpmfiles files, rpmfi *fi);
629b27
 #ifdef __cplusplus
629b27
 }
629b27
 #endif
629b27
-- 
629b27
2.35.1
629b27