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 B56D5138335 for ; Fri, 10 May 2019 07:30:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C0E27E0872; Fri, 10 May 2019 07:30:23 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 944CEE0872 for ; Fri, 10 May 2019 07:30:23 +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 AA256343F2A for ; Fri, 10 May 2019 07:30:21 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3C821549 for ; Fri, 10 May 2019 07:30:14 +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: <1557472812.b61ddadded74e0e7d088999a627dd35ed2ebb92a.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qfile.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: b61ddadded74e0e7d088999a627dd35ed2ebb92a X-VCS-Branch: master Date: Fri, 10 May 2019 07:30:14 +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: a15f99fb-a540-46c1-aa63-fa2d5b0e68d9 X-Archives-Hash: 16e43a8dfb178854a29725cf99db4bd1 commit: b61ddadded74e0e7d088999a627dd35ed2ebb92a Author: Fabian Groffen gentoo org> AuthorDate: Fri May 10 07:20:12 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Fri May 10 07:20:12 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b61ddadd qfile: simply by using tree_get_atom and atom_format Signed-off-by: Fabian Groffen gentoo.org> qfile.c | 75 +++++++++++++++++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/qfile.c b/qfile.c index c451ae4..116c7c4 100644 --- a/qfile.c +++ b/qfile.c @@ -78,11 +78,9 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) { struct qfile_opt_state *state = priv; const char *catname = pkg_ctx->cat_ctx->name; - const char *pkgname = pkg_ctx->name; qfile_args_t *args = &state->args; FILE *fp; const char *base; - char pkg[_Q_PATH_MAX]; depend_atom *atom = NULL; int i; bool path_ok; @@ -93,8 +91,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) short *non_orphans = args->non_orphans; int found = 0; - snprintf(pkg, sizeof(pkg), "%s/%s", catname, pkgname); - /* If exclude_pkg is not NULL, check it. We are looking for files * collisions, and must exclude one package. */ @@ -103,21 +99,15 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) if (state->exclude_atom->CATEGORY && strcmp(state->exclude_atom->CATEGORY, catname)) goto dont_skip_pkg; - atom = atom_explode(pkg); - if (state->exclude_atom->PVR) { - /* see if PVR is exact match */ - if (strcmp(state->exclude_atom->PVR, atom->PVR)) - goto dont_skip_pkg; - } else { - /* see if PN is exact match */ - if (strcmp(state->exclude_atom->PN, atom->PN)) - goto dont_skip_pkg; - } + atom = tree_get_atom(pkg_ctx, false); + if (atom_compare(state->exclude_atom, atom) != EQUAL) + goto dont_skip_pkg; + /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */ if (state->exclude_slot == NULL) - goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */ - tree_pkg_vdb_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen); - rmspace(state->buf); - if (strcmp(state->exclude_slot, state->buf) == 0) + goto qlist_done; + /* retrieve atom, this time with SLOT */ + atom = tree_get_atom(pkg_ctx, true); + if (strcmp(state->exclude_slot, atom->SLOT) == 0) goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */ } dont_skip_pkg: /* End of the package exclusion tests. */ @@ -134,11 +124,7 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) if (!e) continue; - /* basename(3) possibly modifies e->name (if it has trailing - * slashes) but this is not likely since it comes from VDB which - * has normalised everything, so effectively e->name isn't - * touched, however, it /can/ return a pointer to a private - * allocation */ + /* note: this is our own basename which doesn't modify its input */ base = basename(e->name); if (base < e->name || base > (e->name + strlen(e->name))) continue; @@ -163,8 +149,8 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) path_ok = false; if (dir_names[i] && - strncmp(e->name, dir_names[i], dirname_len) == 0 && - dir_names[i][dirname_len] == '\0') + strncmp(e->name, dir_names[i], dirname_len) == 0 && + dir_names[i][dirname_len] == '\0') { /* dir_name == dirname(CONTENTS) */ path_ok = true; @@ -185,8 +171,10 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) _rpath = rpath + real_root_len; if (realpath(fullpath, rpath) == NULL) { if (verbose) { + atom = tree_get_atom(pkg_ctx, false); warnp("Could not read real path of \"%s\" (from %s)", - fullpath, pkg); + fullpath, + atom_format("%[CATEGORY]%[PF]", atom, false)); warn("We'll never know whether \"%s\" was a result " "for your query...", e->name); } @@ -215,26 +203,24 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) continue; if (non_orphans == NULL) { - char slot[126]; + const char *fmt; + + atom = tree_get_atom(pkg_ctx, true); - if (!atom) { - if ((atom = atom_explode(pkg)) == NULL) { - warn("invalid atom %s", pkg); - continue; + if (state->slotted) { + if (verbose) { + fmt = "%[CATEGORY]%[PF]%[SLOT]"; + } else { + fmt = "%[CATEGORY]%[PN]%[SLOT]"; + } + } else { + if (verbose) { + fmt = "%[CATEGORY]%[PF]"; + } else { + fmt = "%[CATEGORY]%[PN]"; } } - if (state->slotted) { - /* XXX: This assumes the buf is big enough. */ - char *slot_hack = slot + 1; - size_t slot_len = sizeof(slot) - 1; - tree_pkg_vdb_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len); - rmspace(slot_hack); - slot[0] = ':'; - } else - slot[0] = '\0'; - printf("%s%s/%s%s%s%s", BOLD, atom->CATEGORY, BLUE, - (verbose ? pkg_ctx->name : atom->PN), - slot, NORM); + printf("%s", atom_format(fmt, atom, false)); if (quiet) puts(""); else @@ -248,9 +234,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) fclose(fp); qlist_done: - if (atom) - atom_implode(atom); - return found; }