From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 30C4B1382C5 for ; Wed, 17 Feb 2021 20:23:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6B7ABE08BB; Wed, 17 Feb 2021 20:23:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 41DF2E08BB for ; Wed, 17 Feb 2021 20:23:36 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CCA2E341949 for ; Wed, 17 Feb 2021 20:23:34 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 08E9F4C0 for ; Wed, 17 Feb 2021 20:23:33 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1613592841.16ff9817f7d68d37e39302dac6f632c306cdce4f.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c libq/tree.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 16ff9817f7d68d37e39302dac6f632c306cdce4f X-VCS-Branch: master Date: Wed, 17 Feb 2021 20:23:33 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: cad3ef77-93fb-4956-9500-ed330c840643 X-Archives-Hash: 8f362084bd688ebb0fab5b4d79098c5c commit: 16ff9817f7d68d37e39302dac6f632c306cdce4f Author: Fabian Groffen gentoo org> AuthorDate: Wed Feb 17 20:14:01 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Wed Feb 17 20:14:01 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=16ff9817 libq/tree: make tree_match_atom return path for each match Along with some changes to make sure returned atoms remain valid (e.g. not getting an expired pointer for category name), build a patch to the returned objects, that should allow opening the ebuild or something. Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 41 +++++++++++++++++++++++++++++++++-------- libq/tree.h | 5 ++++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/libq/tree.c b/libq/tree.c index e41a0cb..293d7f7 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2020 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd - @@ -55,6 +55,10 @@ tree_open_int(const char *sroot, const char *tdir, bool quiet) goto cp_error; } + if (sroot[0] == '/' && sroot[1] == '\0') + sroot = ""; + snprintf(ctx->path, sizeof(ctx->path), "%s/%s", sroot, tdir); + ctx->dir = fdopendir(ctx->tree_fd); if (ctx->dir == NULL) goto cv_error; @@ -128,6 +132,25 @@ tree_open_vdb(const char *sroot, const char *svdb) return ret; } +tree_ctx * +tree_open_ebuild(const char *sroot, const char *portdir) +{ + tree_ctx *ret = tree_open_int(sroot, portdir, true); + if (ret != NULL) { + char buf[_Q_PATH_MAX]; + char *repo = NULL; + size_t repolen = 0; + + snprintf(buf, sizeof(buf), "%s%s/%s", sroot, portdir, portrepo_name); + if (eat_file(buf, &repo, &repolen)) { + (void)rmspace(repo); + ret->repo = repo; + } + ret->cachetype = CACHE_EBUILD; + } + return ret; +} + static const char binpkg_packages[] = "Packages"; tree_ctx * tree_open_binpkg(const char *sroot, const char *spkg) @@ -1491,10 +1514,10 @@ depend_atom * tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) { if (pkg_ctx->atom == NULL) { - pkg_ctx->atom = atom_explode(pkg_ctx->name); + pkg_ctx->atom = + atom_explode_cat(pkg_ctx->name, (char *)pkg_ctx->cat_ctx->name); if (pkg_ctx->atom == NULL) return NULL; - pkg_ctx->atom->CATEGORY = (char *)pkg_ctx->cat_ctx->name; } if (complete) { @@ -1708,14 +1731,15 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int flags) while ((pkg_ctx = tree_next_pkg(C)) != NULL) { \ atom = tree_get_atom(pkg_ctx, \ query->SLOT != NULL || flags & TREE_MATCH_FULL_ATOM); \ -fprintf(stderr, "fbg: %s\n", atom_to_string(atom)); \ if (flags & TREE_MATCH_VIRTUAL || \ - strcmp(atom->CATEGORY, "virtual") != 0) \ + strcmp(atom->CATEGORY, "virtual") != 0) { \ if (atom_compare(atom, query) == EQUAL) { \ - tree_match_ctx *n; \ - n = xzalloc(sizeof(tree_match_ctx)); \ - n->free_atom = false; \ + tree_match_ctx *n = xzalloc(sizeof(tree_match_ctx)); \ n->atom = atom; \ + snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \ + (char *)C->ctx->path, C->name, pkg_ctx->name, \ + C->ctx->cachetype == CACHE_EBUILD ? ".ebuild" : \ + C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : ""); \ if (flags & TREE_MATCH_METADATA) \ n->meta = tree_pkg_read(pkg_ctx); \ n->next = ret; \ @@ -1723,6 +1747,7 @@ fprintf(stderr, "fbg: %s\n", atom_to_string(atom)); \ } \ if (flags & TREE_MATCH_FIRST && ret != NULL) \ break; \ + } \ } \ C->pkg_cur = 0; /* reset to allow another traversal */ \ } diff --git a/libq/tree.h b/libq/tree.h index 900b998..f756fd4 100644 --- a/libq/tree.h +++ b/libq/tree.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2020 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ @@ -24,6 +24,7 @@ typedef struct tree_match_ctx tree_match_ctx; struct tree_ctx { int portroot_fd; int tree_fd; + char path[_Q_PATH_MAX]; DIR *dir; struct dirent **cat_de; size_t cat_cnt; @@ -122,6 +123,7 @@ struct tree_metadata_xml { struct tree_match_ctx { depend_atom *atom; tree_pkg_meta *meta; + char path[_Q_PATH_MAX + 48]; tree_match_ctx *next; int free_atom; }; @@ -131,6 +133,7 @@ typedef int (tree_pkg_cb)(tree_pkg_ctx *, void *priv); tree_ctx *tree_open(const char *sroot, const char *portdir); tree_ctx *tree_open_vdb(const char *sroot, const char *svdb); +tree_ctx *tree_open_ebuild(const char *sroot, const char *portdir); tree_ctx *tree_open_binpkg(const char *sroot, const char *spkg); void tree_close(tree_ctx *ctx); tree_cat_ctx *tree_open_cat(tree_ctx *ctx, const char *name);