diff options
author | Guillem Jover <guillem@debian.org> | 2019-03-04 23:00:18 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2019-11-26 02:42:44 +0100 |
commit | 956272322b1a54a4fc8c539ac4000add8dfb6007 (patch) | |
tree | 192a240f71a0c741eace5d6853e1f0f39a15166f /lib | |
parent | 5aae5e10375d5956d639eaf23a49b842bf109b17 (diff) | |
download | dpkg-956272322b1a54a4fc8c539ac4000add8dfb6007.tar.gz |
dpkg-query: Try to use the description from the available file if not installed
When we have been requested to load the available file, and that
contains a description for a package that is not installed, we should
use that instead of printing the confusing string stating that the
description is not available.
Closes: #43573
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/libdpkg.map | 1 | ||||
-rw-r--r-- | lib/dpkg/pkg-show.c | 33 | ||||
-rw-r--r-- | lib/dpkg/pkg-show.h | 2 |
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index dc58738ea..33297a8bf 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -300,6 +300,7 @@ LIBDPKG_PRIVATE { pkg_name_const; pkg_source_version; pkgbin_synopsis; + pkg_synopsis; pkg_abbrev_want; pkg_abbrev_status; pkg_abbrev_eflag; diff --git a/lib/dpkg/pkg-show.c b/lib/dpkg/pkg-show.c index 569cbf5c2..67e5af404 100644 --- a/lib/dpkg/pkg-show.c +++ b/lib/dpkg/pkg-show.c @@ -224,6 +224,39 @@ pkgbin_synopsis(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len } /** + * Return a string representation of the package synopsis. + * + * The returned string must not be freed, and it's permanently allocated so + * can be used as long as the non-freeing memory pool has not been freed. + * + * It will try to use the installed version, otherwise it will fallback to + * use the available version. + * + * The package synopsis is the short description, but it is not NUL terminated, + * so the output len argument should be used to limit the string length. + * + * @param pkg The package to consider. + * @param[out] len The length of the synopsis string within the description. + * + * @return The string representation. + */ +const char * +pkg_synopsis(const struct pkginfo *pkg, int *len) +{ + const char *pdesc; + + pdesc = pkg->installed.description; + if (!pdesc) + pdesc = pkg->available.description; + if (!pdesc) + pdesc = _("(no description available)"); + + *len = strcspn(pdesc, "\n"); + + return pdesc; +} + +/** * Return a character abbreviated representation of the package want status. * * @param pkg The package to consider. diff --git a/lib/dpkg/pkg-show.h b/lib/dpkg/pkg-show.h index 9ef0ed459..4ac3f5d65 100644 --- a/lib/dpkg/pkg-show.h +++ b/lib/dpkg/pkg-show.h @@ -36,6 +36,8 @@ int pkg_sorter_by_nonambig_name_arch(const void *a, const void *b); const char *pkgbin_synopsis(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len_ret); +const char * +pkg_synopsis(const struct pkginfo *pkg, int *len_ret); int pkg_abbrev_want(const struct pkginfo *pkg); int pkg_abbrev_status(const struct pkginfo *pkg); int pkg_abbrev_eflag(const struct pkginfo *pkg); |