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