aboutsummaryrefslogtreecommitdiff
path: root/quse.c
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2019-12-30 18:21:21 +0100
committerFabian Groffen <grobian@gentoo.org>2019-12-30 18:21:21 +0100
commitc9e89dfa7cc3ae22bc3c731a3d617e4912bd831a (patch)
treead0056af5d34ebb3b6de2221d8d7f3f2e1546282 /quse.c
parentlibq/tree: ensure valid pointers in case of realloc (diff)
downloadportage-utils-c9e89dfa7cc3ae22bc3c731a3d617e4912bd831a.tar.gz
portage-utils-c9e89dfa7cc3ae22bc3c731a3d617e4912bd831a.tar.bz2
portage-utils-c9e89dfa7cc3ae22bc3c731a3d617e4912bd831a.zip
libq/tree: introduce a wrapper for retrieving ebuild metadata
To further hide the difference between trees, add a wrapper around tree_get_meta, which deals with the underlying storage format. This is most notably useful when dealing with vdb-based and binpkgs because they have a specific or more expensive way of retrieval. This can now properly be hidden from the q applets. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Diffstat (limited to 'quse.c')
-rw-r--r--quse.c71
1 files changed, 24 insertions, 47 deletions
diff --git a/quse.c b/quse.c
index df8626e..be34e48 100644
--- a/quse.c
+++ b/quse.c
@@ -412,7 +412,6 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
struct quse_state *state = (struct quse_state *)priv;
depend_atom *atom = NULL; /* pacify compiler */
char buf[8192];
- tree_pkg_meta *meta;
set *use = NULL;
bool match;
char *p;
@@ -439,52 +438,38 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
}
}
- if (state->overlay != NULL) {
- meta = tree_pkg_read(pkg_ctx);
- if (meta == NULL)
+ if (!state->do_licence) {
+ if (tree_pkg_meta_get(pkg_ctx, IUSE) == NULL)
return 0;
- if (meta->IUSE == NULL)
- return 0;
- } else {
- size_t dummy;
-
- meta = xzalloc(sizeof(*meta));
- dummy = 0;
- if (!tree_pkg_vdb_eat(pkg_ctx, "IUSE", &meta->IUSE, &dummy)) {
- free(meta);
- return 0;
+ if (state->do_describe) {
+ portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
+ state->overlay == NULL ? main_overlay : state->overlay,
+ O_RDONLY | O_CLOEXEC | O_PATH);
+ if (portdirfd == -1)
+ return 0;
}
- dummy = 0;
- tree_pkg_vdb_eat(pkg_ctx, "LICENSE", &meta->LICENSE, &dummy);
-
- s = NULL;
- dummy = 0;
- tree_pkg_vdb_eat(pkg_ctx, "USE", &s, &dummy);
- p = s;
- while ((q = strchr(p, (int)' ')) != NULL) {
- *q++ = '\0';
- use = add_set(p, use);
- p = q;
+ /* available when dealing with VDB or binpkgs */
+ if ((p = tree_pkg_meta_get(pkg_ctx, USE)) != NULL) {
+ while ((q = strchr(p, (int)' ')) != NULL) {
+ *q++ = '\0';
+ use = add_set(p, use);
+ p = q;
+ }
+ if (*p != '\0')
+ use = add_set(p, use);
}
- if (*p != '\0')
- use = add_set(p, use);
- free(s);
- }
-
- if (state->do_describe) {
- portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
- state->overlay == NULL ? main_overlay : state->overlay,
- O_RDONLY | O_CLOEXEC | O_PATH);
- if (portdirfd == -1)
+ } else {
+ if (tree_pkg_meta_get(pkg_ctx, LICENSE) == NULL)
return 0;
}
maxlen = 0;
cnt = 0;
match = false;
- q = p = state->do_licence ? meta->LICENSE : meta->IUSE;
+ q = p = state->do_licence ?
+ tree_pkg_meta_get(pkg_ctx, LICENSE) : tree_pkg_meta_get(pkg_ctx, IUSE);
buf[0] = '\0';
v = buf;
w = buf + sizeof(buf);
@@ -567,7 +552,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
printf("%s\n", atom_format(state->fmt, atom));
- q = p = meta->IUSE;
+ q = p = tree_pkg_meta_get(pkg_ctx, IUSE);
buf[0] = '\0';
v = buf;
w = buf + sizeof(buf);
@@ -652,16 +637,8 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
}
}
- if (state->overlay != NULL) {
- tree_close_meta(meta);
- } else {
- free(meta->IUSE);
- if (meta->LICENSE != NULL)
- free(meta->LICENSE);
- free(meta);
- if (use != NULL)
- free_set(use);
- }
+ if (use != NULL)
+ free_set(use);
if (state->do_describe)
close(portdirfd);