Blame 0001-Add-optional-callback-on-directory-changes-during-rp.patch

Florian Festi 94360a
From 186e0ab025b9ad92d900697f611633a6f6162f3b Mon Sep 17 00:00:00 2001
Florian Festi 94360a
From: Panu Matilainen <pmatilai@redhat.com>
Florian Festi 94360a
Date: Wed, 9 Feb 2022 14:47:14 +0200
Florian Festi 94360a
Subject: [PATCH] Add optional callback on directory changes during rpmfi
Florian Festi 94360a
 iteration
Florian Festi 94360a
Florian Festi 94360a
Internal only for now in case we need to fiddle with the API some more,
Florian Festi 94360a
but no reason this couldn't be made public later.
Florian Festi 94360a
---
Florian Festi 94360a
 lib/rpmfi.c          | 24 ++++++++++++++++++++----
Florian Festi 94360a
 lib/rpmfi_internal.h | 17 +++++++++++++++++
Florian Festi 94360a
 2 files changed, 37 insertions(+), 4 deletions(-)
Florian Festi 94360a
Florian Festi 94360a
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
Florian Festi 94360a
index aec8220a3..6c631fdb5 100644
Florian Festi 94360a
--- a/lib/rpmfi.c
Florian Festi 94360a
+++ b/lib/rpmfi.c
Florian Festi 94360a
@@ -53,6 +53,9 @@ struct rpmfi_s {
Florian Festi 94360a
     int intervalStart;		/*!< Start of iterating interval. */
Florian Festi 94360a
     int intervalEnd;		/*!< End of iterating interval. */
Florian Festi 94360a
 
Florian Festi 94360a
+    rpmfiChdirCb onChdir;	/*!< Callback for directory changes */
Florian Festi 94360a
+    void *onChdirData;		/*!< Caller private callback data */
Florian Festi 94360a
+
Florian Festi 94360a
     rpmfiles files;		/*!< File info set */
Florian Festi 94360a
     rpmcpio_t archive;		/*!< Archive with payload */
Florian Festi 94360a
     unsigned char * found;	/*!< Bit field of files found in the archive */
Florian Festi 94360a
@@ -298,11 +301,16 @@ rpm_count_t rpmfiDC(rpmfi fi)
Florian Festi 94360a
     return (fi != NULL ? rpmfilesDC(fi->files) : 0);
Florian Festi 94360a
 }
Florian Festi 94360a
 
Florian Festi 94360a
-#ifdef	NOTYET
Florian Festi 94360a
-int rpmfiDI(rpmfi fi)
Florian Festi 94360a
+int rpmfiSetOnChdir(rpmfi fi, rpmfiChdirCb cb, void *data)
Florian Festi 94360a
 {
Florian Festi 94360a
+    int rc = -1;
Florian Festi 94360a
+    if (fi != NULL) {
Florian Festi 94360a
+	fi->onChdir = cb;
Florian Festi 94360a
+	fi->onChdirData = data;
Florian Festi 94360a
+	rc = 0;
Florian Festi 94360a
+    }
Florian Festi 94360a
+    return rc;
Florian Festi 94360a
 }
Florian Festi 94360a
-#endif
Florian Festi 94360a
 
Florian Festi 94360a
 int rpmfiFX(rpmfi fi)
Florian Festi 94360a
 {
Florian Festi 94360a
@@ -314,9 +322,17 @@ int rpmfiSetFX(rpmfi fi, int fx)
Florian Festi 94360a
     int i = -1;
Florian Festi 94360a
 
Florian Festi 94360a
     if (fi != NULL && fx >= 0 && fx < rpmfilesFC(fi->files)) {
Florian Festi 94360a
+	int dx = fi->j;
Florian Festi 94360a
 	i = fi->i;
Florian Festi 94360a
 	fi->i = fx;
Florian Festi 94360a
 	fi->j = rpmfilesDI(fi->files, fi->i);
Florian Festi 94360a
+	i = fi->i;
Florian Festi 94360a
+
Florian Festi 94360a
+	if (fi->j != dx && fi->onChdir) {
Florian Festi 94360a
+	    int chrc = fi->onChdir(fi, fi->onChdirData);
Florian Festi 94360a
+	    if (chrc < 0)
Florian Festi 94360a
+		i = chrc;
Florian Festi 94360a
+	}
Florian Festi 94360a
     }
Florian Festi 94360a
     return i;
Florian Festi 94360a
 }
Florian Festi 94360a
@@ -1682,9 +1698,9 @@ static rpmfi initIter(rpmfiles files, int itype, int link)
Florian Festi 94360a
     if (files && itype>=0 && itype<=RPMFILEITERMAX) {
Florian Festi 94360a
 	fi = xcalloc(1, sizeof(*fi)); 
Florian Festi 94360a
 	fi->i = -1;
Florian Festi 94360a
+	fi->j = -1;
Florian Festi 94360a
 	fi->files = link ? rpmfilesLink(files) : files;
Florian Festi 94360a
 	fi->next = nextfuncs[itype];
Florian Festi 94360a
-	fi->i = -1;
Florian Festi 94360a
 	if (itype == RPMFI_ITER_BACK) {
Florian Festi 94360a
 	    fi->i = rpmfilesFC(fi->files);
Florian Festi 94360a
 	} else if (itype >=RPMFI_ITER_READ_ARCHIVE
Florian Festi 94360a
diff --git a/lib/rpmfi_internal.h b/lib/rpmfi_internal.h
Florian Festi 94360a
index dccc6ccbe..37f1d45f5 100644
Florian Festi 94360a
--- a/lib/rpmfi_internal.h
Florian Festi 94360a
+++ b/lib/rpmfi_internal.h
Florian Festi 94360a
@@ -13,6 +13,23 @@
Florian Festi 94360a
 extern "C" {
Florian Festi 94360a
 #endif
Florian Festi 94360a
 
Florian Festi 94360a
+/** \ingroup rpmfi
Florian Festi 94360a
+ * Callback on file iterator directory changes
Florian Festi 94360a
+ * @param fi		file info
Florian Festi 94360a
+ * @param data		caller private callback data
Florian Festi 94360a
+ * @return		0 on success, < 0 on error (to stop iteration)
Florian Festi 94360a
+ */
Florian Festi 94360a
+typedef int (*rpmfiChdirCb)(rpmfi fi, void *data);
Florian Festi 94360a
+
Florian Festi 94360a
+/** \ingroup rpmfi
Florian Festi 94360a
+ * Set a callback for directory changes during iteration.
Florian Festi 94360a
+ * @param fi		file info
Florian Festi 94360a
+ * @param cb		callback function
Florian Festi 94360a
+ * @param data		caller private callback data
Florian Festi 94360a
+ * @return		string pool handle (weak reference)
Florian Festi 94360a
+ */
Florian Festi 94360a
+int rpmfiSetOnChdir(rpmfi fi, rpmfiChdirCb cb, void *data);
Florian Festi 94360a
+
Florian Festi 94360a
 /** \ingroup rpmfi
Florian Festi 94360a
  * Return file info set string pool handle
Florian Festi 94360a
  * @param fi		file info
Florian Festi 94360a
-- 
Florian Festi 94360a
2.41.0
Florian Festi 94360a