1 |
commit: 493ec668848a3f7dc74001454957205ff9017879 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jun 12 13:56:20 2021 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jun 12 13:56:20 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=493ec668 |
7 |
|
8 |
libq/tree: better tree_match interaction with binpkgs |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
libq/tree.c | 41 ++++++++++++++++++++++++++++++++--------- |
13 |
1 file changed, 32 insertions(+), 9 deletions(-) |
14 |
|
15 |
diff --git a/libq/tree.c b/libq/tree.c |
16 |
index d7ec882..2180867 100644 |
17 |
--- a/libq/tree.c |
18 |
+++ b/libq/tree.c |
19 |
@@ -1080,6 +1080,10 @@ static tree_pkg_meta * |
20 |
tree_pkg_read(tree_pkg_ctx *pkg_ctx) |
21 |
{ |
22 |
tree_ctx *ctx = pkg_ctx->cat_ctx->ctx; |
23 |
+ tree_pkg_meta *ret = NULL; |
24 |
+ |
25 |
+ if (pkg_ctx->meta != NULL) |
26 |
+ return pkg_ctx->meta; |
27 |
|
28 |
if (pkg_ctx->fd == -1) { |
29 |
if (ctx->cachetype == CACHE_EBUILD || ctx->cachetype == CACHE_BINPKGS) { |
30 |
@@ -1098,19 +1102,22 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx) |
31 |
} |
32 |
|
33 |
if (ctx->cachetype == CACHE_METADATA_MD5) { |
34 |
- return tree_read_file_md5(pkg_ctx); |
35 |
+ ret = tree_read_file_md5(pkg_ctx); |
36 |
} else if (ctx->cachetype == CACHE_METADATA_PMS) { |
37 |
- return tree_read_file_pms(pkg_ctx); |
38 |
+ ret = tree_read_file_pms(pkg_ctx); |
39 |
} else if (ctx->cachetype == CACHE_EBUILD) { |
40 |
- return tree_read_file_ebuild(pkg_ctx); |
41 |
+ ret = tree_read_file_ebuild(pkg_ctx); |
42 |
} else if (ctx->cachetype == CACHE_BINPKGS) { |
43 |
- return tree_read_file_binpkg(pkg_ctx); |
44 |
+ ret = tree_read_file_binpkg(pkg_ctx); |
45 |
} else if (ctx->cachetype == CACHE_PACKAGES) { |
46 |
- return (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs; |
47 |
+ ret = (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs; |
48 |
} |
49 |
|
50 |
- warn("Unknown/unsupported metadata cache type!"); |
51 |
- return NULL; |
52 |
+ pkg_ctx->meta = ret; |
53 |
+ |
54 |
+ if (ret == NULL) |
55 |
+ warn("Unknown/unsupported metadata cache type!"); |
56 |
+ return ret; |
57 |
} |
58 |
|
59 |
static void |
60 |
@@ -1204,6 +1211,12 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn) |
61 |
if (*key == NULL && ctx->cachetype == CACHE_PACKAGES) { |
62 |
ctx->cachetype = CACHE_BINPKGS; |
63 |
pkg_ctx->fd = -1; |
64 |
+ |
65 |
+ /* trigger tree_pkg_read to do something */ |
66 |
+ if ((void *)pkg_ctx->meta != (void *)pkg_ctx->cat_ctx->ctx->pkgs) |
67 |
+ free(pkg_ctx->meta); |
68 |
+ pkg_ctx->meta = NULL; |
69 |
+ |
70 |
pkg_ctx->meta = tree_pkg_read(pkg_ctx); |
71 |
ctx->cachetype = CACHE_PACKAGES; |
72 |
if (pkg_ctx->meta == NULL) { |
73 |
@@ -1653,6 +1666,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv) |
74 |
tree_pkg_ctx *pkg; |
75 |
tree_ctx *tctx = ctx->cat_ctx->ctx; |
76 |
depend_atom *atom = tree_get_atom(ctx, true); |
77 |
+ tree_pkg_meta *meta = tree_pkg_read(ctx); |
78 |
|
79 |
(void)priv; |
80 |
|
81 |
@@ -1671,7 +1685,15 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv) |
82 |
cat_ctx->pkg_ctxs[cat_ctx->pkg_cnt - 1] = |
83 |
pkg = tree_open_pkg(cat_ctx, atom->PF); |
84 |
pkg->atom = atom_clone(atom); |
85 |
- pkg->name = pkg->atom->PF; |
86 |
+ pkg->name = xstrdup(pkg->atom->PF); |
87 |
+ pkg->repo = tctx->repo != NULL ? xstrdup(tctx->repo) : NULL; |
88 |
+ if (meta != NULL) { |
89 |
+ pkg->meta = xmalloc(sizeof(*pkg->meta)); |
90 |
+ memcpy(pkg->meta, meta, sizeof(*pkg->meta)); |
91 |
+ pkg->fd = 0; /* don't try to read, we already got it */ |
92 |
+ } else { |
93 |
+ pkg->meta = NULL; |
94 |
+ } |
95 |
|
96 |
return 0; |
97 |
} |
98 |
@@ -1761,7 +1783,8 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int flags) |
99 |
snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \ |
100 |
(char *)C->ctx->path, C->name, pkg_ctx->name, \ |
101 |
C->ctx->cachetype == CACHE_EBUILD ? ".ebuild" : \ |
102 |
- C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : ""); \ |
103 |
+ C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : \ |
104 |
+ C->ctx->cachetype == CACHE_PACKAGES ? ".tbz2" : ""); \ |
105 |
if (flags & TREE_MATCH_METADATA) \ |
106 |
n->meta = tree_pkg_read(pkg_ctx); \ |
107 |
n->next = ret; \ |