This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=05458bb8d50cb3b0f29e53d2a079f2ef874b8f23 commit 05458bb8d50cb3b0f29e53d2a079f2ef874b8f23 Author: Guillem Jover <guil...@debian.org> AuthorDate: Fri Jun 8 04:15:22 2018 +0200 dpkg-query: Run --list output through a pager if we are on a terminal The current code, checks whether we are running on a terminal, and then truncates the output fields so that it can fit within. This causes data loss and can confuse the user depending where the cut point has happened. Instead we remove that logic, and always redirect the outout through a pager in case we are running on a terminal, which gives full information and does not necessarily emit ugly output. Closes: #898603 --- debian/changelog | 2 + man/dpkg-query.man | 4 -- man/dpkg.man | 5 --- src/querycmd.c | 110 +++++++++++++++-------------------------------------- 4 files changed, 33 insertions(+), 88 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1d46bb361..497cfb81e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -83,6 +83,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium to output other deb822 formatted data in a deterministic way. * Require both standard input and output to be connected to a terminal to use a pager. + * Run dpkg-query --list output through a pager if we are on a terminal, + instead of truncating it, to avoid data loss. Closes: #898603 * Architecture support: - Add support for riscv64 CPU. Closes: #822914 Thanks to Manuel A. Fernandez Montecelo <m...@debian.org> diff --git a/man/dpkg-query.man b/man/dpkg-query.man index 46cf7c28c..36f83580f 100644 --- a/man/dpkg-query.man +++ b/man/dpkg-query.man @@ -321,10 +321,6 @@ be used as the \fBdpkg\fP data directory. Sets the color mode (since dpkg 1.18.5). The currently accepted values are: \fBauto\fP (default), \fBalways\fP and \fBnever\fP. -.TP -\fBCOLUMNS\fP -This setting influences the output of the \fB\-\-list\fP option by changing -the width of its output. . .SH SEE ALSO .BR dpkg (1). diff --git a/man/dpkg.man b/man/dpkg.man index 772c1b324..bf7b5a96a 100644 --- a/man/dpkg.man +++ b/man/dpkg.man @@ -879,11 +879,6 @@ The program \fBdpkg\fP will execute when displaying the conffiles. .B SHELL The program \fBdpkg\fP will execute when starting a new interactive shell. .TP -.B COLUMNS -Sets the number of columns \fBdpkg\fP should use when displaying formatted -text. -Currently only used by \fB\-\-list\fP. -.TP .B DPKG_COLORS Sets the color mode (since dpkg 1.18.5). The currently accepted values are: \fBauto\fP (default), \fBalways\fP and diff --git a/src/querycmd.c b/src/querycmd.c index 76ab99e66..bfb521a2e 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -27,7 +27,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <sys/ioctl.h> #if HAVE_LOCALE_H #include <locale.h> @@ -38,7 +37,6 @@ #include <fcntl.h> #include <dirent.h> #include <fnmatch.h> -#include <termios.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> @@ -53,6 +51,7 @@ #include <dpkg/string.h> #include <dpkg/path.h> #include <dpkg/file.h> +#include <dpkg/pager.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> #include <dpkg/db-fsys.h> @@ -63,38 +62,6 @@ static const char *showformat = "${binary:Package}\t${Version}\n"; static int opt_loadavail = 0; -static int getwidth(void) { - int fd; - long res; - struct winsize ws; - const char *columns; - char *endptr; - - columns = getenv("COLUMNS"); - if (columns) { - errno = 0; - res = strtol(columns, &endptr, 10); - if (errno == 0 && columns != endptr && *endptr == '\0' && - res > 0 && res < INT_MAX) - return res; - } - - if (!isatty(1)) - return -1; - else { - res = 80; - - fd = open("/dev/tty", O_RDONLY); - if (fd != -1) { - if (ioctl(fd, TIOCGWINSZ, &ws) == 0) - res = ws.ws_col; - close(fd); - } - - return res; - } -} - static int pkg_array_match_patterns(struct pkg_array *array, pkg_array_visitor_func *pkg_visitor, void *pkg_data, @@ -155,56 +122,36 @@ struct list_format { static void list_format_init(struct list_format *fmt, struct pkg_array *array) { - int w; + int i; if (fmt->nw != 0) return; - w = getwidth(); - if (w == -1) { - int i; + fmt->nw = 14; + fmt->vw = 12; + fmt->aw = 12; + fmt->dw = 33; - fmt->nw = 14; - fmt->vw = 12; - fmt->aw = 12; - fmt->dw = 33; - - for (i = 0; i < array->n_pkgs; i++) { - int plen, vlen, alen, dlen; - - if (array->pkgs[i] == NULL) - continue; - - plen = str_width(pkg_name(array->pkgs[i], pnaw_nonambig)); - vlen = str_width(versiondescribe(&array->pkgs[i]->installed.version, - vdew_nonambig)); - alen = str_width(dpkg_arch_describe(array->pkgs[i]->installed.arch)); - pkgbin_synopsis(array->pkgs[i], &array->pkgs[i]->installed, &dlen); - - if (plen > fmt->nw) - fmt->nw = plen; - if (vlen > fmt->vw) - fmt->vw = vlen; - if (alen > fmt->aw) - fmt->aw = alen; - if (dlen > fmt->dw) - fmt->dw = dlen; - } - } else { - w -= 80; - /* Let's not try to deal with terminals that are too small. */ - if (w < 0) - w = 0; - /* Halve that so we can add it to both the name and description. */ - w >>= 1; - /* Name width. */ - fmt->nw = (14 + (w / 2)); - /* Version width. */ - fmt->vw = (12 + (w / 4)); - /* Architecture width. */ - fmt->aw = (12 + (w / 4)); - /* Description width. */ - fmt->dw = (33 + w); + for (i = 0; i < array->n_pkgs; i++) { + int plen, vlen, alen, dlen; + + if (array->pkgs[i] == NULL) + continue; + + plen = str_width(pkg_name(array->pkgs[i], pnaw_nonambig)); + vlen = str_width(versiondescribe(&array->pkgs[i]->installed.version, + vdew_nonambig)); + alen = str_width(dpkg_arch_describe(array->pkgs[i]->installed.arch)); + pkgbin_synopsis(array->pkgs[i], &array->pkgs[i]->installed, &dlen); + + if (plen > fmt->nw) + fmt->nw = plen; + if (vlen > fmt->vw) + fmt->vw = vlen; + if (alen > fmt->aw) + fmt->aw = alen; + if (dlen > fmt->dw) + fmt->dw = dlen; } } @@ -306,6 +253,7 @@ listpackages(const char *const *argv) int i; int rc = 0; struct list_format fmt; + struct pager *pager; if (!opt_loadavail) modstatdb_open(msdbrw_readonly); @@ -317,6 +265,8 @@ listpackages(const char *const *argv) memset(&fmt, 0, sizeof(fmt)); + pager = pager_spawn(_("showing package list on pager"), NULL); + if (!*argv) { for (i = 0; i < array.n_pkgs; i++) { pkg = array.pkgs[i]; @@ -332,6 +282,8 @@ listpackages(const char *const *argv) m_output(stdout, _("<standard output>")); m_output(stderr, _("<standard error>")); + pager_reap(pager); + pkg_array_destroy(&array); modstatdb_shutdown(); -- Dpkg.Org's dpkg