From 5c97d7f83f56015d6a37934cee4e55ed8d747890 Mon Sep 17 00:00:00 2001
From: chantra <chantr4@gmail.com>
Date: Tue, 8 Feb 2022 16:57:25 -0800
Subject: [PATCH 13/30] [plugin] add `plugin_fsm_file_install_func` plugin hook
This hook is to be called when installing individual files from the RPM.
---
lib/Makefile.in | 51 ++++++++++++++++++++++++++----------------------
lib/rpmplugin.h | 5 +++++
lib/rpmplugins.c | 37 +++++++++++++++++++++++++++++++++++
lib/rpmplugins.h | 15 ++++++++++++++
4 files changed, 85 insertions(+), 23 deletions(-)
diff --git a/lib/Makefile.in b/lib/Makefile.in
index e1965d8..c4bba25 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -173,10 +173,11 @@ am__librpm_la_SOURCES_DIST = backend/dbi.c backend/dbi.h \
rpmlock.c rpmlock.h misc.h relocation.c rpmscript.h \
rpmscript.c rpmchroot.c rpmchroot.h rpmplugins.c rpmplugins.h \
rpmplugin.h rpmug.c rpmug.h rpmtriggers.h rpmtriggers.c \
- rpmvs.c rpmvs.h backend/db3.c backend/bdb_ro.c \
- backend/ndb/glue.c backend/ndb/rpmpkg.c backend/ndb/rpmpkg.h \
- backend/ndb/rpmidx.c backend/ndb/rpmidx.h backend/ndb/rpmxdb.c \
- backend/ndb/rpmxdb.h backend/sqlite.c
+ rpmvs.c rpmvs.h rpmextents.c rpmextents_internal.h \
+ backend/db3.c backend/bdb_ro.c backend/ndb/glue.c \
+ backend/ndb/rpmpkg.c backend/ndb/rpmpkg.h backend/ndb/rpmidx.c \
+ backend/ndb/rpmidx.h backend/ndb/rpmxdb.c backend/ndb/rpmxdb.h \
+ backend/sqlite.c
am__dirstamp = $(am__leading_dot)dirstamp
@BDB_TRUE@am__objects_1 = backend/db3.lo
@BDB_RO_TRUE@am__objects_2 = backend/bdb_ro.lo
@@ -192,8 +193,8 @@ am_librpm_la_OBJECTS = backend/dbi.lo backend/dummydb.lo \
rpmlead.lo rpmps.lo rpmprob.lo rpmrc.lo rpmte.lo rpmts.lo \
rpmfs.lo signature.lo transaction.lo verify.lo rpmlock.lo \
relocation.lo rpmscript.lo rpmchroot.lo rpmplugins.lo rpmug.lo \
- rpmtriggers.lo rpmvs.lo $(am__objects_1) $(am__objects_2) \
- $(am__objects_3) $(am__objects_4)
+ rpmtriggers.lo rpmvs.lo rpmextents.lo $(am__objects_1) \
+ $(am__objects_2) $(am__objects_3) $(am__objects_4)
librpm_la_OBJECTS = $(am_librpm_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -228,21 +229,21 @@ am__depfiles_remade = ./$(DEPDIR)/cpio.Plo ./$(DEPDIR)/depends.Plo \
./$(DEPDIR)/relocation.Plo ./$(DEPDIR)/rpmal.Plo \
./$(DEPDIR)/rpmchecksig.Plo ./$(DEPDIR)/rpmchroot.Plo \
./$(DEPDIR)/rpmdb.Plo ./$(DEPDIR)/rpmds.Plo \
- ./$(DEPDIR)/rpmfi.Plo ./$(DEPDIR)/rpmfs.Plo \
- ./$(DEPDIR)/rpmgi.Plo ./$(DEPDIR)/rpminstall.Plo \
- ./$(DEPDIR)/rpmlead.Plo ./$(DEPDIR)/rpmlock.Plo \
- ./$(DEPDIR)/rpmplugins.Plo ./$(DEPDIR)/rpmprob.Plo \
- ./$(DEPDIR)/rpmps.Plo ./$(DEPDIR)/rpmrc.Plo \
- ./$(DEPDIR)/rpmscript.Plo ./$(DEPDIR)/rpmtd.Plo \
- ./$(DEPDIR)/rpmte.Plo ./$(DEPDIR)/rpmtriggers.Plo \
- ./$(DEPDIR)/rpmts.Plo ./$(DEPDIR)/rpmug.Plo \
- ./$(DEPDIR)/rpmvs.Plo ./$(DEPDIR)/signature.Plo \
- ./$(DEPDIR)/tagexts.Plo ./$(DEPDIR)/tagname.Plo \
- ./$(DEPDIR)/transaction.Plo ./$(DEPDIR)/verify.Plo \
- backend/$(DEPDIR)/bdb_ro.Plo backend/$(DEPDIR)/db3.Plo \
- backend/$(DEPDIR)/dbi.Plo backend/$(DEPDIR)/dbiset.Plo \
- backend/$(DEPDIR)/dummydb.Plo backend/$(DEPDIR)/sqlite.Plo \
- backend/ndb/$(DEPDIR)/glue.Plo \
+ ./$(DEPDIR)/rpmextents.Plo ./$(DEPDIR)/rpmfi.Plo \
+ ./$(DEPDIR)/rpmfs.Plo ./$(DEPDIR)/rpmgi.Plo \
+ ./$(DEPDIR)/rpminstall.Plo ./$(DEPDIR)/rpmlead.Plo \
+ ./$(DEPDIR)/rpmlock.Plo ./$(DEPDIR)/rpmplugins.Plo \
+ ./$(DEPDIR)/rpmprob.Plo ./$(DEPDIR)/rpmps.Plo \
+ ./$(DEPDIR)/rpmrc.Plo ./$(DEPDIR)/rpmscript.Plo \
+ ./$(DEPDIR)/rpmtd.Plo ./$(DEPDIR)/rpmte.Plo \
+ ./$(DEPDIR)/rpmtriggers.Plo ./$(DEPDIR)/rpmts.Plo \
+ ./$(DEPDIR)/rpmug.Plo ./$(DEPDIR)/rpmvs.Plo \
+ ./$(DEPDIR)/signature.Plo ./$(DEPDIR)/tagexts.Plo \
+ ./$(DEPDIR)/tagname.Plo ./$(DEPDIR)/transaction.Plo \
+ ./$(DEPDIR)/verify.Plo backend/$(DEPDIR)/bdb_ro.Plo \
+ backend/$(DEPDIR)/db3.Plo backend/$(DEPDIR)/dbi.Plo \
+ backend/$(DEPDIR)/dbiset.Plo backend/$(DEPDIR)/dummydb.Plo \
+ backend/$(DEPDIR)/sqlite.Plo backend/ndb/$(DEPDIR)/glue.Plo \
backend/ndb/$(DEPDIR)/rpmidx.Plo \
backend/ndb/$(DEPDIR)/rpmpkg.Plo \
backend/ndb/$(DEPDIR)/rpmxdb.Plo
@@ -589,8 +590,9 @@ librpm_la_SOURCES = backend/dbi.c backend/dbi.h backend/dummydb.c \
signature.h transaction.c verify.c rpmlock.c rpmlock.h misc.h \
relocation.c rpmscript.h rpmscript.c rpmchroot.c rpmchroot.h \
rpmplugins.c rpmplugins.h rpmplugin.h rpmug.c rpmug.h \
- rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h $(am__append_1) \
- $(am__append_4) $(am__append_5) $(am__append_8)
+ rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h rpmextents.c \
+ rpmextents_internal.h $(am__append_1) $(am__append_4) \
+ $(am__append_5) $(am__append_8)
librpm_la_LDFLAGS = -version-info $(rpm_version_info)
librpm_la_LIBADD = $(top_builddir)/rpmio/librpmio.la @WITH_POPT_LIB@ \
@WITH_CAP_LIB@ @WITH_ACL_LIB@ @LIBINTL@ $(am__append_2) \
@@ -751,6 +753,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmchroot.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmdb.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmds.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmextents.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmfi.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmfs.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpmgi.Plo@am__quote@ # am--include-marker
@@ -981,6 +984,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/rpmchroot.Plo
-rm -f ./$(DEPDIR)/rpmdb.Plo
-rm -f ./$(DEPDIR)/rpmds.Plo
+ -rm -f ./$(DEPDIR)/rpmextents.Plo
-rm -f ./$(DEPDIR)/rpmfi.Plo
-rm -f ./$(DEPDIR)/rpmfs.Plo
-rm -f ./$(DEPDIR)/rpmgi.Plo
@@ -1080,6 +1084,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/rpmchroot.Plo
-rm -f ./$(DEPDIR)/rpmdb.Plo
-rm -f ./$(DEPDIR)/rpmds.Plo
+ -rm -f ./$(DEPDIR)/rpmextents.Plo
-rm -f ./$(DEPDIR)/rpmfi.Plo
-rm -f ./$(DEPDIR)/rpmfs.Plo
-rm -f ./$(DEPDIR)/rpmgi.Plo
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
index fd81aec8d..877db81f3 100644
--- a/lib/rpmplugin.h
+++ b/lib/rpmplugin.h
@@ -60,6 +60,10 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin plugin, rpmfi fi,
int fd, const char* path,
const char *dest,
mode_t file_mode, rpmFsmOp op);
+typedef rpmRC (*plugin_fsm_file_install_func)(rpmPlugin plugin, rpmfi fi,
+ const char* path,
+ mode_t file_mode, rpmFsmOp op);
+
typedef struct rpmPluginHooks_s * rpmPluginHooks;
struct rpmPluginHooks_s {
@@ -80,6 +84,7 @@ struct rpmPluginHooks_s {
plugin_fsm_file_pre_func fsm_file_pre;
plugin_fsm_file_post_func fsm_file_post;
plugin_fsm_file_prepare_func fsm_file_prepare;
+ plugin_fsm_file_install_func fsm_file_install;
};
#ifdef __cplusplus
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
index 3da3097af..850a025a0 100644
--- a/lib/rpmplugins.c
+++ b/lib/rpmplugins.c
@@ -435,3 +435,40 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
return rc;
}
+
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
+ const char *path, mode_t file_mode,
+ rpmFsmOp op)
+{
+ plugin_fsm_file_install_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_install);
+ if (hookFunc) {
+ hook_rc = hookFunc(plugin, fi, path, file_mode, op);
+ if (hook_rc == RPMRC_FAIL) {
+ rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_install 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 39762c376..5365cf698 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -168,6 +168,21 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
int fd, const char *path, const char *dest,
mode_t mode, rpmFsmOp op);
+/** \ingroup rpmplugins
+ * Call the fsm file install plugin hook
+ * @param plugins plugins structure
+ * @param fi file info iterator (or NULL)
+ * @param path file object path
+ * @param file_mode file object mode
+ * @param op file operation + associated flags
+ * @return RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
+ const char* path, mode_t file_mode,
+ rpmFsmOp op);
+
+
#ifdef __cplusplus
}
#endif
--
2.35.1