1 |
commit: 90fe066073722807b6a48f391e6500b28398830b |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jun 14 09:30:23 2021 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jun 14 09:30:23 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=90fe0660 |
7 |
|
8 |
libq/tree: make tree_match_atom produce valid meta for binpkgs |
9 |
|
10 |
copy meta appropriately in populate_cb when we deal with binpkgs |
11 |
directly |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
libq/tree.c | 54 ++++++++++++++++++++++++++++++++++++------------------ |
16 |
1 file changed, 36 insertions(+), 18 deletions(-) |
17 |
|
18 |
diff --git a/libq/tree.c b/libq/tree.c |
19 |
index 5a505f2..847a343 100644 |
20 |
--- a/libq/tree.c |
21 |
+++ b/libq/tree.c |
22 |
@@ -546,7 +546,10 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) |
23 |
tree_ctx *ctx = cat_ctx->ctx; |
24 |
tree_pkg_ctx *ret = NULL; |
25 |
|
26 |
- if (ctx->cachetype == CACHE_EBUILD) { |
27 |
+ if (ctx->do_sort && cat_ctx->pkg_ctxs != NULL) { |
28 |
+ /* bypass to use the cache if it exists */ |
29 |
+ ret = tree_next_pkg_int(cat_ctx); |
30 |
+ } else if (ctx->cachetype == CACHE_EBUILD) { |
31 |
char *p; |
32 |
|
33 |
/* serve *.ebuild files each as separate pkg_ctx with name set |
34 |
@@ -1600,9 +1603,6 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) |
35 |
} |
36 |
pkg_ctx->atom->REPO = pkg_ctx->repo; |
37 |
} |
38 |
- |
39 |
- if (meta != NULL) |
40 |
- tree_close_meta(meta); |
41 |
} |
42 |
|
43 |
/* this is a bit atom territory, but since we pulled in SLOT we |
44 |
@@ -1659,12 +1659,12 @@ tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms) |
45 |
static int |
46 |
tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv) |
47 |
{ |
48 |
- set *cache = priv; |
49 |
- tree_cat_ctx *cat_ctx; |
50 |
- tree_pkg_ctx *pkg; |
51 |
- tree_ctx *tctx = ctx->cat_ctx->ctx; |
52 |
- depend_atom *atom = tree_get_atom(ctx, true); |
53 |
- tree_pkg_meta *meta = tree_pkg_read(ctx); |
54 |
+ tree_cat_ctx *cat_ctx; |
55 |
+ tree_pkg_ctx *pkg; |
56 |
+ set *cache = priv; |
57 |
+ tree_ctx *tctx = ctx->cat_ctx->ctx; |
58 |
+ depend_atom *atom = tree_get_atom(ctx, true); |
59 |
+ tree_pkg_meta *meta = tree_pkg_read(ctx); |
60 |
|
61 |
(void)priv; |
62 |
|
63 |
@@ -1686,10 +1686,31 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv) |
64 |
pkg->name = xstrdup(pkg->atom->PF); |
65 |
pkg->repo = tctx->repo != NULL ? xstrdup(tctx->repo) : NULL; |
66 |
if (meta != NULL) { |
67 |
+ pkg->fd = -2; /* don't try to read, we fill it in here */ |
68 |
pkg->meta = xmalloc(sizeof(*pkg->meta)); |
69 |
memcpy(pkg->meta, meta, sizeof(*pkg->meta)); |
70 |
- pkg->meta->Q__data = NULL; /* avoid free here (just to be sure) */ |
71 |
- pkg->fd = -2; /* don't try to read, we already got it */ |
72 |
+ if (ctx->cat_ctx->ctx->cachetype == CACHE_PACKAGES) { |
73 |
+ pkg->meta->Q__data = NULL; /* avoid free here (just to be sure) */ |
74 |
+ } else { /* CACHE_BINPKG */ |
75 |
+ char **newdata; |
76 |
+ int elems; |
77 |
+ size_t datasize = (size_t)meta->Q__eclasses_; |
78 |
+ |
79 |
+ pkg->meta->Q__data = xmalloc(sizeof(char) * datasize); |
80 |
+ memcpy(pkg->meta->Q__data, meta->Q__data, datasize); |
81 |
+ |
82 |
+ /* re-position keys */ |
83 |
+ newdata = (char **)pkg->meta; |
84 |
+ elems = sizeof(tree_pkg_meta) / sizeof(char *); |
85 |
+ while (elems-- > 1) /* skip Q__data itself */ |
86 |
+ if (newdata[elems] != NULL) |
87 |
+ newdata[elems] = pkg->meta->Q__data + |
88 |
+ (newdata[elems] - meta->Q__data); |
89 |
+ |
90 |
+ /* drop garbage used for Q__data admin in original case */ |
91 |
+ pkg->meta->Q__eclasses_ = NULL; |
92 |
+ pkg->meta->Q__md5_ = NULL; |
93 |
+ } |
94 |
} else { |
95 |
pkg->meta = NULL; |
96 |
} |
97 |
@@ -1728,12 +1749,9 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, int flags) |
98 |
else |
99 |
cache = create_set(); |
100 |
|
101 |
- if (ctx->cachetype == CACHE_PACKAGES) |
102 |
- tree_foreach_packages(ctx, |
103 |
- tree_match_atom_cache_populate_cb, cache); |
104 |
- else /* BINPKG */ |
105 |
- tree_foreach_pkg(ctx, |
106 |
- tree_match_atom_cache_populate_cb, cache, true, NULL); |
107 |
+ tree_foreach_pkg(ctx, |
108 |
+ tree_match_atom_cache_populate_cb, cache, true, NULL); |
109 |
+ |
110 |
ctx->do_sort = true; /* turn it back on */ |
111 |
ctx->cache.all_categories = true; |