commit: 04978409eb34973d3af6ce0592fd623e82ea6573
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May 25 10:33:59 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May 25 10:33:59 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=04978409
libq/tree: allow tree_foreach_packages to be called multiple times
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/libq/tree.c b/libq/tree.c
index d901fc6..4b9109e 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1293,6 +1293,22 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb
callback, void *priv)
tree_pkg_meta meta;
depend_atom *atom = NULL;
+ /* re-read the contents, this is necessary to make it possible to
+ * call this function multiple times
+ * TODO: generate an internal in-memory tree when cache is enabled */
+ if (ctx->pkgs == NULL || ctx->pkgs[0] == '\0') {
+ int fd = openat(ctx->tree_fd, binpkg_packages, O_RDONLY |
O_CLOEXEC);
+ if (!eat_file_fd(fd, &ctx->pkgs, &ctx->pkgslen)) {
+ if (ctx->pkgs != NULL) {
+ free(ctx->pkgs);
+ ctx->pkgs = NULL;
+ }
+ close(fd);
+ return 1;
+ }
+ close(fd);
+ }
+
memset(&meta, 0, sizeof(meta));
do {