commit: 5531d5c97a27c002abfcc1bd229d0716bba4b2e3 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Fri May 17 14:34:09 2019 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Fri May 17 14:34:09 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5531d5c9
qfile: allow matching basenames to objects by default one can now do qfile qfile to find app-portage/portage-utils updated the manpage somewhat Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> man/include/qfile-01-owners.include | 30 ++++++----- man/include/qfile-02-orphans.include | 15 +++--- man/include/qfile-03-ROOT.include | 20 ++++---- man/include/qfile-05-collisions.include | 8 +-- man/include/qfile.desc | 23 +++++++++ man/include/qfile.optdesc.yaml | 4 ++ man/qfile.1 | 88 ++++++++++++++++++++------------- qfile.c | 35 ++++++++----- 8 files changed, 140 insertions(+), 83 deletions(-) diff --git a/man/include/qfile-01-owners.include b/man/include/qfile-01-owners.include index a4bdc76..39b1e03 100644 --- a/man/include/qfile-01-owners.include +++ b/man/include/qfile-01-owners.include @@ -1,16 +1,14 @@ .SH "FINDING FILE OWNERS" .PP -This is the default behavior of \fBqfile\fP. It will list the packages which -own the files (or directories, or symlinks, or anything else Portage can -install) you are querying. Query items may be file paths or simple file -names when the \fB\-b\fP option is used. -By default, output includes packages names and the complete paths to -the matching files. If using \fB\-\-exact\fP, versions of the packages will -also be shown. At the contrary, when using \fB\-\-quiet\fP, only package -names are listed, without files paths. Finally, \fB\-\-verbose\fP is similar -to \fB\-\-exact\fP, but may add a few warnings. The return status of -\fBqfile\fP will be \fI0\fP as soon as an owning package has been found for -one of the query items. +This is the default behavior of \fBqfile\fP. It will list the packages +which own the files (or directories, or symlinks, or anything else +Portage can install) you are querying. Query items may be file paths or +simple file names. By default, output includes packages names and the +complete paths to the matching files. If using \fB\-\-verbose\fP, +versions of the packages will also be shown. In contrast, when using +\fB\-\-quiet\fP, only package names are listed, without files paths. +The return status of \fBqfile\fP will be \fI0\fP as soon as an owning +package has been found for one of the query items. .PP Find names of package(s) owning "/bin/bash": .nf\fI @@ -20,17 +18,17 @@ Find names of package(s) owning "/bin/bash": .PP Find package(s) owning any file named "bash", and show paths of this files: .nf\fI - $ qfile -b bash - app-shells/bash (/bin/bash) - app-shells/bash (/etc/bash) + $ qfile -d bash + app-shells/bash: /bin/bash + app-shells/bash: /etc/bash .fi .PP Find packages(s) owning the file named "bash" in the current directory. Also display their exact version: .nf\fI $ cd /bin - $ qfile -e ./bash - app-shells/bash-3.1_p17 (/bin/bash) + $ qfile -v ./bash + app-shells/bash-3.1_p17: /bin/bash .fi .PP Find the package(s) owning the libraries needed by the Bash binary: diff --git a/man/include/qfile-02-orphans.include b/man/include/qfile-02-orphans.include index ca23796..f6754aa 100644 --- a/man/include/qfile-02-orphans.include +++ b/man/include/qfile-02-orphans.include @@ -1,13 +1,12 @@ .SH "FINDING ORPHAN FILES" .PP -\fBqfile\fP can also, with the \fB\-\-orphans\fP option, find files which are -not owned by any package. This behavior is the opposite of the usual file -owner search: the output is the list of query items for which no reference has -been found in your installed packages database. The \fB\-\-exact\fP option has -no effect in this mode, whereas \fB\-\-verbose\fP may add a few warning -messages. As for \fB\-\-quiet\fP, it will completly turn off the output, -leaving just a silent test command, which returns \fI0\fP if and only if -there was no orphan in your query items. +\fBqfile\fP can also, with the \fB\-\-orphans\fP option, find files +which are not owned by any package. This behaviour is the opposite of +the usual file owner search: the output is the list of query items for +which no reference has been found in your installed packages database. +As for \fB\-\-quiet\fP, it will completly turn off the output, leaving +just a silent test command, which returns \fI0\fP if and only if there +was no orphan in your query items. .PP Find the orphan libtool files of your system: .nf\fI diff --git a/man/include/qfile-03-ROOT.include b/man/include/qfile-03-ROOT.include index 61d965d..3bfbe51 100644 --- a/man/include/qfile-03-ROOT.include +++ b/man/include/qfile-03-ROOT.include @@ -1,7 +1,7 @@ .SH "$ROOT HANDLING" .PP By setting the \fIROOT\fP environment variable, you can force \fBqfile\fP to -work in the sytem of your choice. This example shows queries for owner of +work in the sytem of your choice. This example shows queries for owner of "/bin/sh", first on your main system, and then on a system mounted on "/mnt": .nf\fI $ qfile -q /bin/sh @@ -10,25 +10,25 @@ work in the sytem of your choice. This example shows queries for owner of sys-apps/busybox .fi .PP -Note that the query item is "/bin/sh" in both commands: by default, what -\fBqfile\fP looks for is file paths as they are recorded in the packages +Note that the query item is "/bin/sh" in both commands: by default, what +\fBqfile\fP looks for is file paths as they are recorded in the packages database of the target system, and this paths don't include \fI$ROOT\fP. -If, at the contrary, you want to query files with their current actual -paths (including the mount point), you should add the \fB\-\-root\-prefix\fP +If, on the contrary, you want to query files with their current actual +paths (including the mount point), you should add the \fB\-\-root\-prefix\fP (\fB\-R\fP) option: .nf\fI $ ROOT=/mnt qfile -Rq /mnt/bin/sh sys-apps/busybox .fi .PP -The other difference beetween defaults and \fB\-R\fP queries is the output -of files paths. The former doesn't include the \fI$ROOT\fP prefix, and the -later does: +The other difference between defaults and \fB\-R\fP queries is the output +of files paths. The former doesn't include the \fI$ROOT\fP prefix, and the +latter does: .nf\fI $ ROOT=/mnt qfile sh - sys-apps/busybox (/bin/sh) + sys-apps/busybox: /bin/sh $ ROOT=/mnt qfile -R sh - sys-apps/busybox (/mnt/bin/sh) + sys-apps/busybox: /mnt/bin/sh .fi .PP Sure, the same differences hold when querying for orphan files: diff --git a/man/include/qfile-05-collisions.include b/man/include/qfile-05-collisions.include index 1b8672d..dd2c1d8 100644 --- a/man/include/qfile-05-collisions.include +++ b/man/include/qfile-05-collisions.include @@ -4,9 +4,9 @@ A last option of \fBqfile\fP is \fB\-\-exclude\fP (\fB\-x\fP), which will makes it skip one particular package when doing its files owners search. This option takes one argument, which can be a package name (\fBbash\fP or \fBapp\-shells/bash\fP), or a versioned package (\fBbash\-3.2_p9\-r1\fP or -\fBapp\-shells/bash\-3.2_p9\-r1\fP), or a slotted package (\fBbash:0\fP or -\fBapp\-shells/bash:0\fP). It is useful for finding file collisions beetween -packages (ie., comparing the contents of one package with the contents of all +\fBapp\-shells/bash\-3.2_p9\-r1\fP), or a slotted package (\fBbash:0\fP or +\fBapp\-shells/bash:0\fP). It is useful for finding file collisions between +packages (ie.\ comparing the contents of one package with the contents of all the others). .PP For example, the following script will search collisions between all your @@ -26,7 +26,7 @@ installed packages. Be careful, this will takes time: done .fi .PP -An other example is the following script, which can be used to check that a +An other example is the following script, which can be used to check that a binary package (.tbz2) has no conflict with any of your installed packages, but the one it may replace (same name and slot), if any: .nf\fI diff --git a/man/include/qfile.desc b/man/include/qfile.desc index 08d4bb3..614d8a0 100644 --- a/man/include/qfile.desc +++ b/man/include/qfile.desc @@ -2,3 +2,26 @@ packages must be installed, thus the search is for any file on the filesystem, to what package that file belongs. It allows to identify which package installed a certain file. +.P +The arguments to \fIqfile\fR can be absolute or relative paths and +individual files. By default arguments are interpreted as follows: +.RS +.IP "absolute path" +The path is matched against directories, symlinks and objects. +.IP "relative path" +The path is resolved against the current directory, and after that +matched like an absolute path. +.IP "-d option in use" +The basename (last component) of the argument path is matched to any +directory, symlink or object whose basename matches. This effectively +means it matches directories as well as symlinks and objects unlike when +\fB-d\fR is not given and a basename is given as argument. +.IP basename +The basename is first attempted to be located in the current directory. +If an object exists by that name, it is matched like an absolute path. +If no such object exists, the name is matched against the basename of +any symlink or object. For matching directories, use \fB-d\fR. +.RE +.P +After version \fB0.74\fR of portage-utils, the \fB-b\fR option was +renamed to \fB-d\fR. diff --git a/man/include/qfile.optdesc.yaml b/man/include/qfile.optdesc.yaml index cb1cd7a..66ee885 100644 --- a/man/include/qfile.optdesc.yaml +++ b/man/include/qfile.optdesc.yaml @@ -5,3 +5,7 @@ verbose: | quiet: | Don't print matching file for matches, just the package. Don't report about orphan files. +dir: | + Only consider basename of argument and also match directories, this + option makes qlist ignore any path component given in the arguments + if present. diff --git a/man/qfile.1 b/man/qfile.1 index 1440bd7..8d5b7dc 100644 --- a/man/qfile.1 +++ b/man/qfile.1 @@ -10,6 +10,29 @@ qfile \- list all pkgs owning files packages must be installed, thus the search is for any file on the filesystem, to what package that file belongs. It allows to identify which package installed a certain file. +.P +The arguments to \fIqfile\fR can be absolute or relative paths and +individual files. By default arguments are interpreted as follows: +.RS +.IP "absolute path" +The path is matched against directories, symlinks and objects. +.IP "relative path" +The path is resolved against the current directory, and after that +matched like an absolute path. +.IP "-d option in use" +The basename (last component) of the argument path is matched to any +directory, symlink or object whose basename matches. This effectively +means it matches directories as well as symlinks and objects unlike when +\fB-d\fR is not given and a basename is given as argument. +.IP basename +The basename is first attempted to be located in the current directory. +If an object exists by that name, it is matched like an absolute path. +If no such object exists, the name is matched against the basename of +any symlink or object. For matching directories, use \fB-d\fR. +.RE +.P +After version \fB0.74\fR of portage-utils, the \fB-b\fR option was +renamed to \fB-d\fR. .SH OPTIONS .TP \fB\-S\fR, \fB\-\-slots\fR @@ -18,8 +41,10 @@ Display installed packages with slots. \fB\-R\fR, \fB\-\-root\-prefix\fR Assume arguments are already prefixed by $ROOT. .TP -\fB\-b\fR, \fB\-\-basename\fR -Match any component of the path. +\fB\-d\fR, \fB\-\-dir\fR +Only consider basename of argument and also match directories, this +option makes qlist ignore any path component given in the arguments +if present. .TP \fB\-o\fR, \fB\-\-orphans\fR List orphan files. @@ -49,17 +74,15 @@ Print this help and exit. Print version and exit. .SH "FINDING FILE OWNERS" .PP -This is the default behavior of \fBqfile\fP. It will list the packages which -own the files (or directories, or symlinks, or anything else Portage can -install) you are querying. Query items may be file paths or simple file -names when the \fB\-b\fP option is used. -By default, output includes packages names and the complete paths to -the matching files. If using \fB\-\-exact\fP, versions of the packages will -also be shown. At the contrary, when using \fB\-\-quiet\fP, only package -names are listed, without files paths. Finally, \fB\-\-verbose\fP is similar -to \fB\-\-exact\fP, but may add a few warnings. The return status of -\fBqfile\fP will be \fI0\fP as soon as an owning package has been found for -one of the query items. +This is the default behavior of \fBqfile\fP. It will list the packages +which own the files (or directories, or symlinks, or anything else +Portage can install) you are querying. Query items may be file paths or +simple file names. By default, output includes packages names and the +complete paths to the matching files. If using \fB\-\-verbose\fP, +versions of the packages will also be shown. In contrast, when using +\fB\-\-quiet\fP, only package names are listed, without files paths. +The return status of \fBqfile\fP will be \fI0\fP as soon as an owning +package has been found for one of the query items. .PP Find names of package(s) owning "/bin/bash": .nf\fI @@ -69,17 +92,17 @@ Find names of package(s) owning "/bin/bash": .PP Find package(s) owning any file named "bash", and show paths of this files: .nf\fI - $ qfile -b bash - app-shells/bash (/bin/bash) - app-shells/bash (/etc/bash) + $ qfile -d bash + app-shells/bash: /bin/bash + app-shells/bash: /etc/bash .fi .PP Find packages(s) owning the file named "bash" in the current directory. Also display their exact version: .nf\fI $ cd /bin - $ qfile -e ./bash - app-shells/bash-3.1_p17 (/bin/bash) + $ qfile -v ./bash + app-shells/bash-3.1_p17: /bin/bash .fi .PP Find the package(s) owning the libraries needed by the Bash binary: @@ -91,14 +114,13 @@ Find the package(s) owning the libraries needed by the Bash binary: .fi .SH "FINDING ORPHAN FILES" .PP -\fBqfile\fP can also, with the \fB\-\-orphans\fP option, find files which are -not owned by any package. This behavior is the opposite of the usual file -owner search: the output is the list of query items for which no reference has -been found in your installed packages database. The \fB\-\-exact\fP option has -no effect in this mode, whereas \fB\-\-verbose\fP may add a few warning -messages. As for \fB\-\-quiet\fP, it will completly turn off the output, -leaving just a silent test command, which returns \fI0\fP if and only if -there was no orphan in your query items. +\fBqfile\fP can also, with the \fB\-\-orphans\fP option, find files +which are not owned by any package. This behaviour is the opposite of +the usual file owner search: the output is the list of query items for +which no reference has been found in your installed packages database. +As for \fB\-\-quiet\fP, it will completly turn off the output, leaving +just a silent test command, which returns \fI0\fP if and only if there +was no orphan in your query items. .PP Find the orphan libtool files of your system: .nf\fI @@ -128,7 +150,7 @@ work in the sytem of your choice. This example shows queries for owner of Note that the query item is "/bin/sh" in both commands: by default, what \fBqfile\fP looks for is file paths as they are recorded in the packages database of the target system, and this paths don't include \fI$ROOT\fP. -If, at the contrary, you want to query files with their current actual +If, on the contrary, you want to query files with their current actual paths (including the mount point), you should add the \fB\-\-root\-prefix\fP (\fB\-R\fP) option: .nf\fI @@ -136,14 +158,14 @@ paths (including the mount point), you should add the \fB\-\-root\-prefix\fP sys-apps/busybox .fi .PP -The other difference beetween defaults and \fB\-R\fP queries is the output +The other difference between defaults and \fB\-R\fP queries is the output of files paths. The former doesn't include the \fI$ROOT\fP prefix, and the -later does: +latter does: .nf\fI $ ROOT=/mnt qfile sh - sys-apps/busybox (/bin/sh) + sys-apps/busybox: /bin/sh $ ROOT=/mnt qfile -R sh - sys-apps/busybox (/mnt/bin/sh) + sys-apps/busybox: /mnt/bin/sh .fi .PP Sure, the same differences hold when querying for orphan files: @@ -160,8 +182,8 @@ it skip one particular package when doing its files owners search. This option takes one argument, which can be a package name (\fBbash\fP or \fBapp\-shells/bash\fP), or a versioned package (\fBbash\-3.2_p9\-r1\fP or \fBapp\-shells/bash\-3.2_p9\-r1\fP), or a slotted package (\fBbash:0\fP or -\fBapp\-shells/bash:0\fP). It is useful for finding file collisions beetween -packages (ie., comparing the contents of one package with the contents of all +\fBapp\-shells/bash:0\fP). It is useful for finding file collisions between +packages (ie.\ comparing the contents of one package with the contents of all the others). .PP For example, the following script will search collisions between all your diff --git a/qfile.c b/qfile.c index 5a9f7c5..d321a59 100644 --- a/qfile.c +++ b/qfile.c @@ -20,11 +20,11 @@ #include "rmspace.h" #include "tree.h" -#define QFILE_FLAGS "boRx:S" COMMON_FLAGS +#define QFILE_FLAGS "doRx:S" COMMON_FLAGS static struct option const qfile_long_opts[] = { {"slots", no_argument, NULL, 'S'}, {"root-prefix", no_argument, NULL, 'R'}, - {"basename", no_argument, NULL, 'b'}, + {"dir", no_argument, NULL, 'd'}, {"orphans", no_argument, NULL, 'o'}, {"exclude", a_argument, NULL, 'x'}, COMMON_LONG_OPTS @@ -32,7 +32,7 @@ static struct option const qfile_long_opts[] = { static const char * const qfile_opts_help[] = { "Display installed packages with slots", "Assume arguments are already prefixed by $ROOT", - "Match any component of the path", + "Also match directories for single component arguments", "List orphan files", "Don't look in package <arg> (used with --orphans)", COMMON_OPTS_HELP @@ -191,14 +191,25 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) /* real_dir_name == realpath(dirname(CONTENTS)) */ path_ok = true; } - } else if (state->basename) { + } + + if (!path_ok && state->basename) { path_ok = true; - } else if (state->pwd && dir_names[i] == NULL) { + } + + if (!path_ok && state->pwd && dir_names[i] == NULL) { /* try to match file in current directory */ if (strncmp(e->name, state->pwd, dirname_len) == 0 && state->pwd[dirname_len] == '\0') path_ok = true; } + + if (!path_ok && dir_names[i] == NULL && real_dir_names[i] == NULL) { + /* try basename match */ + if (e->type != CONTENTS_DIR) + path_ok = true; + } + if (!path_ok) continue; @@ -401,15 +412,16 @@ int qfile_main(int argc, char **argv) while ((i = GETOPT_LONG(QFILE, qfile, "")) != -1) { switch (i) { COMMON_GETOPTS_CASES(qfile) - case 'S': state.slotted = true; break; - case 'b': state.basename = true; break; - case 'o': state.orphans = true; break; - case 'R': state.assume_root_prefix = true; break; + case 'S': state.slotted = true; break; + case 'd': state.basename = true; break; + case 'o': state.orphans = true; break; + case 'R': state.assume_root_prefix = true; break; case 'x': if (state.exclude_pkg) err("--exclude can only be used once."); state.exclude_pkg = xstrdup(optarg); - if ((state.exclude_slot = strchr(state.exclude_pkg, ':')) != NULL) + state.exclude_slot = strchr(state.exclude_pkg, ':'); + if (state.exclude_slot != NULL) *state.exclude_slot++ = '\0'; state.exclude_atom = atom_explode(optarg); if (!state.exclude_atom) @@ -426,8 +438,7 @@ int qfile_main(int argc, char **argv) state.buf = xmalloc(state.buflen); if (state.assume_root_prefix) { /* Get a copy of $ROOT, with no trailing slash - * (this one is just for qfile(...) output) - */ + * (this one is just for qfile(...) output) */ size_t lastc = strlen(portroot) - 1; state.root = xstrdup(portroot); if (state.root[lastc] == '/')