From 956272322b1a54a4fc8c539ac4000add8dfb6007 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 4 Mar 2019 23:00:18 +0100 Subject: 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 --- lib/dpkg/libdpkg.map | 1 + lib/dpkg/pkg-show.c | 33 +++++++++++++++++++++++++++++++++ lib/dpkg/pkg-show.h | 2 ++ 3 files changed, 36 insertions(+) (limited to 'lib') 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 @@ -223,6 +223,39 @@ pkgbin_synopsis(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len return pdesc; } +/** + * 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. * 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); -- cgit v1.2.3