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