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 5923D138334 for ; Sun, 29 Dec 2019 12:35:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8AF1DE09CE; Sun, 29 Dec 2019 12:35:21 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 5FF22E09CE for ; Sun, 29 Dec 2019 12:35:21 +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 AEF1334DCA8 for ; Sun, 29 Dec 2019 12:35:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3AC953C for ; Sun, 29 Dec 2019 12:35:17 +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: <1577622441.10729f3630faaf79d2e4eaf77ea4bc957fa8c8aa.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: configure.ac qlist.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 10729f3630faaf79d2e4eaf77ea4bc957fa8c8aa X-VCS-Branch: master Date: Sun, 29 Dec 2019 12:35:17 +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: f619ba7f-998c-4ea7-a91e-ecdef3d6c0e7 X-Archives-Hash: 60694277ef45d848a9ed905aac5dd1c2 commit: 10729f3630faaf79d2e4eaf77ea4bc957fa8c8aa Author: Fabian Groffen gentoo org> AuthorDate: Sun Dec 29 12:27:21 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun Dec 29 12:27:21 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=10729f36 qlist: add support for listing contents from binpkgs Read CONTENTS straight out of the xpak archive to provide the same listing capabilities as for VDB. Signed-off-by: Fabian Groffen gentoo.org> configure.ac | 3 ++- qlist.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 0577d07..0efdf3e 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,8 @@ LT_INIT AC_SUBST([LIBTOOL_DEPS]) AC_CHECK_FUNCS_ONCE(m4_flatten([ - scandirat + fmemopen + scandirat ])) AC_ARG_WITH([eprefix], [AS_HELP_STRING([--with-eprefix], [path for Gentoo/Prefix project])]) diff --git a/qlist.c b/qlist.c index 30c0c6f..3f20ced 100644 --- a/qlist.c +++ b/qlist.c @@ -19,6 +19,7 @@ #include "atom.h" #include "contents.h" #include "tree.h" +#include "xpak.h" #include "xregex.h" #define QLIST_FLAGS "IkSRUcDedosF:" COMMON_FLAGS @@ -315,6 +316,7 @@ struct qlist_opt_state { depend_atom **atoms; bool exact:1; bool all:1; + bool do_binpkgs:1; bool just_pkgname:1; bool show_dir:1; bool show_obj:1; @@ -327,6 +329,33 @@ struct qlist_opt_state { const char *fmt; }; +struct qlist_xpakcbctx { + const char *key; + char *retdata; + size_t retlen; +}; + +static void +_qlist_xpakcb( + void *ctx, + char *pathname, + int pathname_len, + int data_offset, + int data_len, + char *data) +{ + struct qlist_xpakcbctx *xctx = ctx; + (void)pathname_len; + + /* see if this path matches what we're looking for */ + if (strcmp(pathname, xctx->key) != 0) + return; + + xctx->retdata = xrealloc(xctx->retdata, data_len + 1); + memcpy(xctx->retdata, data + data_offset, data_len + 1); + xctx->retlen = data_len; +} + static int qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) { @@ -334,6 +363,11 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) int i; FILE *fp; depend_atom *atom; + struct qlist_xpakcbctx cbctx = { + .key = "CONTENTS", + .retdata = NULL, + .retlen = 0, + }; /* see if this cat/pkg is requested */ if (!state->all) { @@ -358,7 +392,31 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) printf("%s %sCONTENTS%s:\n", atom_format(state->fmt, atom), DKBLUE, NORM); - fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS"); + if (state->do_binpkgs) { + char xpak[_Q_PATH_MAX]; + int ret; + snprintf(xpak, sizeof(xpak), "%s/%s/%s/%s-%s.tbz2", + portroot, pkgdir, atom->CATEGORY, atom->PN, + atom->PR_int > 0 ? atom->PVR : atom->PV); + ret = xpak_extract(xpak, &cbctx, &_qlist_xpakcb); + if (ret != 0 || cbctx.retdata == NULL) + fp = NULL; + else +#ifdef HAVE_FMEMOPEN + fp = fmemopen(cbctx.retdata, cbctx.retlen, "r"); +#else + { + /* resort to writing a file in tmpspace */ + fp = tmpfile(); + if (fp != NULL) { + fwrite(cbctx.retdata, 1, cbctx.retlen, fp); + fseek(fp, 0, SEEK_SET); + } + } +#endif + } else { + fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS"); + } if (fp == NULL) return 1; @@ -398,6 +456,8 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) } } fclose(fp); + if (state->do_binpkgs && cbctx.retdata != NULL) + free(cbctx.retdata); return 1; } @@ -410,13 +470,13 @@ int qlist_main(int argc, char **argv) int show_slots = 0; bool show_repo = false; bool do_columns = false; - bool do_binpkgs = false; char qfmt[128]; struct qlist_opt_state state = { .argc = argc, .argv = argv, .exact = false, .all = false, + .do_binpkgs = false, .just_pkgname = false, .show_dir = false, .show_obj = false, @@ -432,7 +492,7 @@ int qlist_main(int argc, char **argv) switch (i) { COMMON_GETOPTS_CASES(qlist) case 'I': state.just_pkgname = true; break; - case 'k': do_binpkgs = true; break; + case 'k': state.do_binpkgs = true; break; case 'S': state.just_pkgname = true; show_slots++; break; case 'R': state.just_pkgname = show_repo = true; break; case 'U': state.just_pkgname = state.show_umap = true; break; @@ -488,7 +548,7 @@ int qlist_main(int argc, char **argv) state.buf = xmalloc(state.buflen); state.atoms = xcalloc(argc - optind, sizeof(*state.atoms)); ret = 1; - if (do_binpkgs) + if (state.do_binpkgs) vdb = tree_open_binpkg(portroot, pkgdir); else vdb = tree_open_vdb(portroot, portvdb);