alexk / rpms / rpm

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