* [gentoo-commits] proj/portage-utils:master commit in: /, man/, man/include/
@ 2021-03-13 20:32 Fabian Groffen
0 siblings, 0 replies; 2+ messages in thread
From: Fabian Groffen @ 2021-03-13 20:32 UTC (permalink / raw
To: gentoo-commits
commit: 7dc2cc4bfaf2bbb943c45bc8171843a523cea7e5
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 13 20:30:48 2021 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Mar 13 20:30:48 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7dc2cc4b
q: show masking reason from comments when using -vv with -m
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
main.c | 1 -
man/include/q.optdesc.yaml | 5 ++--
man/q.1 | 7 +++---
q.c | 58 +++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/main.c b/main.c
index a68af63..ceab587 100644
--- a/main.c
+++ b/main.c
@@ -677,7 +677,6 @@ read_one_repos_conf(const char *repos_conf, char **primary)
main_repo = NULL;
repo = NULL;
- line = 0;
for (p = strtok_r(buf, "\n", &s); p != NULL; p = strtok_r(NULL, "\n", &s))
{
/* trim trailing whitespace, remove comments, locate = */
diff --git a/man/include/q.optdesc.yaml b/man/include/q.optdesc.yaml
index cde6eed..468ffa9 100644
--- a/man/include/q.optdesc.yaml
+++ b/man/include/q.optdesc.yaml
@@ -10,5 +10,6 @@ envvar: |
variable name and the value is printed as a shell-style declaration.
masks: |
Print the masks from package.mask files found. Use \fI-v\fR to see
- the source (file) where the mask was declared. Additional arguments
- are treated as atom selectors which must match the masks.
+ the source (file) where the mask was declared. Use multiple
+ \fI-v\fR to print the comment right before the mask. Additional
+ arguments are treated as atom selectors which must match the masks.
diff --git a/man/q.1 b/man/q.1
index 2979cab..f43be6f 100644
--- a/man/q.1
+++ b/man/q.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH q "1" "Feb 2021" "Gentoo Foundation" "q"
+.TH q "1" "Mar 2021" "Gentoo Foundation" "q"
.SH NAME
q \- invoke a portage utility applet
.SH SYNOPSIS
@@ -35,8 +35,9 @@ variable name and the value is printed as a shell-style declaration.
.TP
\fB\-m\fR, \fB\-\-masks\fR
Print the masks from package.mask files found. Use \fI-v\fR to see
-the source (file) where the mask was declared. Additional arguments
-are treated as atom selectors which must match the masks.
+the source (file) where the mask was declared. Use multiple
+\fI-v\fR to print the comment right before the mask. Additional
+arguments are treated as atom selectors which must match the masks.
.TP
\fB\-\-root\fR \fI<arg>\fR
Set the ROOT env var.
diff --git a/q.c b/q.c
index a6a9a0b..e514b0c 100644
--- a/q.c
+++ b/q.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
@@ -288,6 +288,11 @@ int q_main(int argc, char **argv)
size_t n;
int j;
bool match;
+ char *lastmfile = NULL;
+ long lastcbeg = 0;
+ long lastcend = 0;
+ char *buf = NULL;
+ size_t buflen = 0;
depend_atom *atom;
depend_atom *qatom;
@@ -313,16 +318,63 @@ int q_main(int argc, char **argv)
if (!match)
continue;
+ if (verbose > 1) {
+ char *mfile = (char *)array_get_elem(files, n);
+ char *l;
+ char *s = NULL;
+ long line = 0;
+ long cbeg = 0;
+ long cend = 0;
+
+ s = l = strchr(mfile, ':');
+ /* p cannot be NULL, just crash if something's wrong */
+ (void)strtol(l + 1, &l, 10);
+ if (*l == ':')
+ cbeg = strtol(l + 1, &l, 10);
+ if (*l == '-')
+ cend = strtol(l + 1, &l, 10);
+ if (cend < cbeg)
+ cend = cbeg = 0;
+
+ if (lastmfile == NULL ||
+ strncmp(lastmfile, mfile, s - mfile + 1) != 0 ||
+ lastcbeg != cbeg || lastcend != cend)
+ {
+ *s = '\0';
+ if (buf != NULL)
+ *buf = '\0';
+ eat_file(mfile, &buf, &buflen);
+ *s = ':';
+
+ line = 0;
+ for (l = buf; (s = strchr(l, '\n')) != NULL; l = s + 1)
+ {
+ line++;
+ if (line >= cbeg && line <= cend)
+ printf("%.*s\n", (int)(s - l), l);
+ if (line > cend)
+ break;
+ }
+ }
+ lastmfile = mfile;
+ lastcbeg = cbeg;
+ lastcend = cend;
+ }
printf("%s", atom_format(
"%[pfx]%[CAT]%[PF]%[SLOT]%[SUBSLOT]%[sfx]%[USE]%[REPO]",
atom));
- if (verbose)
+
+ if (verbose == 1) {
printf(" [%s]\n", (char *)array_get_elem(files, n));
- else
+ } else {
printf("\n");
+ }
atom_implode(atom);
}
+ if (buf != NULL)
+ free(buf);
+
xarrayfree_int(masks);
xarrayfree_int(files);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/portage-utils:master commit in: /, man/, man/include/
@ 2025-04-18 20:47 Fabian Groffen
0 siblings, 0 replies; 2+ messages in thread
From: Fabian Groffen @ 2025-04-18 20:47 UTC (permalink / raw
To: gentoo-commits
commit: b7fe0ef1f162c7076c7e04afa706e16d4c6ff8e0
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 18 20:45:07 2025 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Apr 18 20:45:07 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b7fe0ef1
qfile: add -L option to resolve symlinks in VDB entries
This is mostly useful in usr-merge situations where e.g. /bin is a
symlink to usr/bin, and app-shells/bash installs into /bin/bash. This
records /bin/bash in the VDB, but the actual on-disk location is
/usr/bin/bash.
Closes: https://github.com/gentoo/portage-utils/pull/22
Closes: https://github.com/gentoo/portage-utils/pull/32
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
man/include/qfile.optdesc.yaml | 6 ++++
man/qfile.1 | 9 +++++-
qfile.c | 68 +++++++++++++++++++++++-------------------
3 files changed, 51 insertions(+), 32 deletions(-)
diff --git a/man/include/qfile.optdesc.yaml b/man/include/qfile.optdesc.yaml
index 9e1d24b..249da71 100644
--- a/man/include/qfile.optdesc.yaml
+++ b/man/include/qfile.optdesc.yaml
@@ -9,3 +9,9 @@ dir: |
Only consider basename of argument and also match directories, this
option makes qlist ignore any path component given in the arguments
if present.
+follow: |
+ Follow symlinks in both input as well as VDB stored entries. This
+ is useful in situations such as usr-merge where files are stored in
+ locations which contain a symlink traversal, e.g. /bin/bash. By
+ default only the input arguments are resolved to make an exact match
+ with the VDB. Turning this option on may affect performance.
diff --git a/man/qfile.1 b/man/qfile.1
index 21aa77d..204f55d 100644
--- a/man/qfile.1
+++ b/man/qfile.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH qfile "1" "Jan 2024" "Gentoo Foundation" "qfile"
+.TH qfile "1" "Apr 2025" "Gentoo Foundation" "qfile"
.SH NAME
qfile \- list all pkgs owning files
.SH SYNOPSIS
@@ -38,6 +38,13 @@ renamed to \fB-d\fR.
\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR
Print matched atom using given format string.
.TP
+\fB\-L\fR, \fB\-\-follow\fR
+Follow symlinks in both input as well as VDB stored entries. This
+is useful in situations such as usr-merge where files are stored in
+locations which contain a symlink traversal, e.g. /bin/bash. By
+default only the input arguments are resolved to make an exact match
+with the VDB. Turning this option on may affect performance.
+.TP
\fB\-S\fR, \fB\-\-slots\fR
Display installed packages with slots.
.TP
diff --git a/qfile.c b/qfile.c
index 084ead0..af931d8 100644
--- a/qfile.c
+++ b/qfile.c
@@ -21,9 +21,10 @@
#include "rmspace.h"
#include "tree.h"
-#define QFILE_FLAGS "F:doRx:SP" COMMON_FLAGS
+#define QFILE_FLAGS "F:LdoRx:SP" COMMON_FLAGS
static struct option const qfile_long_opts[] = {
{"format", a_argument, NULL, 'F'},
+ {"follow", no_argument, NULL, 'L'},
{"slots", no_argument, NULL, 'S'},
{"root-prefix", no_argument, NULL, 'R'},
{"dir", no_argument, NULL, 'd'},
@@ -34,6 +35,7 @@ static struct option const qfile_long_opts[] = {
};
static const char * const qfile_opts_help[] = {
"Print matched atom using given format string",
+ "Follow symlinks in CONTENTS entries (slower)",
"Display installed packages with slots",
"Assume arguments are already prefixed by $ROOT",
"Also match directories for single component arguments",
@@ -77,6 +79,7 @@ struct qfile_opt_state {
char *exclude_slot;
depend_atom *exclude_atom;
bool basename;
+ bool followlinks;
bool orphans;
bool assume_root_prefix;
bool skip_plibreg;
@@ -172,6 +175,9 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
qfile_str_len_t *real_dir_names = args->realdirnames;
short *non_orphans = args->non_orphans;
int *results = args->results;
+ const char *_rpath;
+ char rpath[_Q_PATH_MAX + 1];
+ char fullpath[_Q_PATH_MAX + 1];
char *line;
char *savep;
const char *base;
@@ -238,27 +244,9 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
path_ok = false;
- if (dir_names[i].len == dirname_len &&
- memcmp(e->name, dir_names[i].str, dir_names[i].len) == 0)
- {
- /* dir_name == dirname(CONTENTS) */
- path_ok = true;
- } else if (real_dir_names[i].len == dirname_len &&
- memcmp(e->name, real_dir_names[i].str,
- real_dir_names[i].len) == 0)
- {
- /* real_dir_name == dirname(CONTENTS) */
- path_ok = true;
- } else if (state->real_root_len > 0) {
- char rpath[_Q_PATH_MAX + 1];
- char *_rpath;
- char fullpath[_Q_PATH_MAX + 1];
- char *real_root = state->real_root;
- size_t real_root_len = state->real_root_len;
-
+ if (state->followlinks) {
snprintf(fullpath, sizeof(fullpath), "%s%s",
- real_root, e->name);
- _rpath = rpath + real_root_len;
+ state->real_root, e->name);
if (realpath(fullpath, rpath) == NULL) {
if (verbose) {
atom = tree_get_atom(pkg_ctx, false);
@@ -268,20 +256,37 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
warn("We'll never know whether \"%s\" was a result "
"for your query...", e->name);
}
- } else if (!qfile_is_prefix(rpath, real_root, real_root_len)) {
+ break;
+ }
+ if (state->real_root_len > 0 &&
+ !qfile_is_prefix(rpath,
+ state->real_root, state->real_root_len))
+ {
if (verbose)
warn("Real path of \"%s\" is not under ROOT: %s",
fullpath, rpath);
- } else if (dir_names[i].len > 0 &&
- real_dir_names[i].len == 0 &&
- strcmp(_rpath, dir_names[i].str) == 0) {
- /* dir_name == realpath(dirname(CONTENTS)) */
- path_ok = true;
- } else if (real_dir_names[i].len > 0 &&
- strcmp(_rpath, real_dir_names[i].str) == 0) {
- /* real_dir_name == realpath(dirname(CONTENTS)) */
- path_ok = true;
+ break;
}
+ _rpath = rpath + state->real_root_len;
+ dirname_len = strlen(_rpath) - 1 - base_names[i].len;
+ } else {
+ _rpath = e->name;
+ }
+
+ if (real_dir_names[i].len == dirname_len &&
+ memcmp(_rpath, real_dir_names[i].str,
+ real_dir_names[i].len) == 0)
+ {
+ /* real_dir_name == dirname(CONTENTS) */
+ path_ok = true;
+ }
+ else if ((!state->followlinks ||
+ real_dir_names[i].len == 0) &&
+ dir_names[i].len == dirname_len &&
+ memcmp(_rpath, dir_names[i].str, dir_names[i].len) == 0)
+ {
+ /* dir_name == dirname(CONTENTS) */
+ path_ok = true;
}
if (!path_ok && state->basename)
@@ -513,6 +518,7 @@ int qfile_main(int argc, char **argv)
COMMON_GETOPTS_CASES(qfile)
case 'F': state.format = optarg; /* fall through */
case 'S': state.need_full_atom = true; break;
+ case 'L': state.followlinks = true; break;
case 'd': state.basename = true; break;
case 'o': state.orphans = true; break;
case 'R': state.assume_root_prefix = true; break;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-18 20:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 20:47 [gentoo-commits] proj/portage-utils:master commit in: /, man/, man/include/ Fabian Groffen
-- strict thread matches above, loose matches on Subject: below --
2021-03-13 20:32 Fabian Groffen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox