Parcourir la source

libdpkg: Add short Description and Status virtual field variants

This adds support for show:Summary and show:Status-Abbrev virtual
output fields. They get namespaced with “show:” to not stomp over
possible fields with the same name coming from binary package or
databases, which would make them inaccessible from dpkg-query.

Closes: #192619, #427945
Guillem Jover il y a 16 ans
Parent
commit
255417d275
3 fichiers modifiés avec 33 ajouts et 0 suppressions
  1. 2 0
      debian/changelog
  2. 29 0
      lib/dpkg/pkg-format.c
  3. 2 0
      man/dpkg-query.1

+ 2 - 0
debian/changelog

@@ -43,6 +43,8 @@ dpkg (1.16.2) UNRELEASED; urgency=low
     instead of dh_install, the former does not abort on empty glob expansion.
   * Do not use absolute paths for programs in perl and shell code.
   * Add missing ‘*’ in asprintf() and vasprintf() compat declarations.
+  * Add support for virtual output fields show:Summary and show:Status-Abbrev.
+    Closes: #192619, #427945
 
   [ Raphaël Hertzog ]
   * Update Dpkg::Shlibs to look into multiarch paths when cross-building

+ 29 - 0
lib/dpkg/pkg-format.c

@@ -30,6 +30,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/parsedump.h>
+#include <dpkg/pkg-show.h>
 #include <dpkg/pkg-format.h>
 
 enum pkg_format_type {
@@ -201,7 +202,35 @@ pkg_format_parse(const char *fmt)
 	return head;
 }
 
+static void
+virt_status_abbrev(struct varbuf *vb,
+                   const struct pkginfo *pkg, const struct pkgbin *pkgbin,
+                   enum fwriteflags flags, const struct fieldinfo *fip)
+{
+	if (pkgbin != &pkg->installed)
+		return;
+
+	varbuf_add_char(vb, pkg_abbrev_want(pkg));
+	varbuf_add_char(vb, pkg_abbrev_status(pkg));
+	varbuf_add_char(vb, pkg_abbrev_eflag(pkg));
+}
+
+static void
+virt_summary(struct varbuf *vb,
+             const struct pkginfo *pkg, const struct pkgbin *pkgbin,
+             enum fwriteflags flags, const struct fieldinfo *fip)
+{
+	const char *desc;
+	int len;
+
+	desc = pkg_summary(pkg, &len);
+
+	varbuf_add_buf(vb, desc, len);
+}
+
 const struct fieldinfo virtinfos[] = {
+	{ "show:Summary",       NULL, virt_summary },
+	{ "show:Status-Abbrev", NULL, virt_status_abbrev },
 	{ NULL },
 };
 

+ 2 - 0
man/dpkg-query.1

@@ -179,6 +179,8 @@ fields or fields stored in the binary package end up in it):
     \fBTriggers\-Awaited\fP (internal)
     \fBTriggers\-Pending\fP (internal)
     \fBVersion\fP
+    \fBshow:Summary\fP (virtual)
+    \fBshow:Status-Abbrev\fP (virtual)
 .fi
 
 The default format string is \(lq\fB${Package}\et${Version}\en\fP\(rq.