summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2019-03-04 23:00:18 +0100
committerGuillem Jover <guillem@debian.org>2019-11-26 02:42:44 +0100
commit956272322b1a54a4fc8c539ac4000add8dfb6007 (patch)
tree192a240f71a0c741eace5d6853e1f0f39a15166f
parent5aae5e10375d5956d639eaf23a49b842bf109b17 (diff)
downloaddpkg-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
-rw-r--r--debian/changelog2
-rw-r--r--lib/dpkg/libdpkg.map1
-rw-r--r--lib/dpkg/pkg-show.c33
-rw-r--r--lib/dpkg/pkg-show.h2
-rw-r--r--src/querycmd.c4
5 files changed, 40 insertions, 2 deletions
diff --git a/debian/changelog b/debian/changelog
index b66d3c00f..2fa7c28f6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,6 +26,8 @@ dpkg (1.20.0) UNRELEASED; urgency=medium
* libdpkg, dpkg: Use new versiondescribe_c() for non-localizable call sites,
such as when writing to a log, which should not be localized.
Reported by Julien Cristau <jcristau@debian.org>.
+ * dpkg-query: Try to use the package synopsis from the available file if
+ not installed. Closes: #43573
* Perl modules:
- Dpkg::Source::Package: Verify original tarball signatures at build time.
- Dpkg::BuildFlags: Add new unset() method.
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);
diff --git a/src/querycmd.c b/src/querycmd.c
index 472d87f79..eba5e53ef 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -142,7 +142,7 @@ list_format_init(struct list_format *fmt, struct pkg_array *array)
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);
+ pkg_synopsis(array->pkgs[i], &dlen);
if (plen > fmt->nw)
fmt->nw = plen;
@@ -232,7 +232,7 @@ pkg_array_list_item(struct pkg_array *array, struct pkginfo *pkg, void *pkg_data
list_format_init(fmt, array);
list_format_print_header(fmt);
- pdesc = pkgbin_synopsis(pkg, &pkg->installed, &l);
+ pdesc = pkg_synopsis(pkg, &l);
l = min(l, fmt->dw);
list_format_print(fmt,