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=46136dbf6811efdb1383940a04fd4575afada65f

commit 46136dbf6811efdb1383940a04fd4575afada65f
Author: Guillem Jover <[email protected]>
AuthorDate: Mon Dec 31 19:27:16 2018 +0100

    libdpkg: Add new db-fsys:Files and db-fsys:Last-Modified virtual fields
    
    This will make it possible to access the filesystem entries per package
    from anything that queries the database, such as «dpkg-query --show».
---
 debian/changelog          |  1 +
 lib/dpkg/db-ctrl-format.c |  2 +-
 lib/dpkg/db-ctrl.h        |  2 +-
 lib/dpkg/pkg-format.c     | 58 +++++++++++++++++++++++++++++++++++++++++++++++
 man/dpkg-query.man        |  8 +++++++
 5 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index f65ac0f9c..36fb657ba 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -52,6 +52,7 @@ dpkg (1.19.3) UNRELEASED; urgency=medium
     track and report back parse errors, so that we can give more descriptive
     messages.
   * libdpkg: Detect unsupported tar entry types to give better error messages.
+  * libdpkg: Add new db-fsys:Files and db-fsys:Last-Modified virtual fields.
   * Perl modules:
     - Dpkg::Changelog::Debian: Preserve modelines at EOF. Closes: #916056
       Thanks to Chris Lamb <[email protected]> for initial test cases.
diff --git a/lib/dpkg/db-ctrl-format.c b/lib/dpkg/db-ctrl-format.c
index 256c7b7e4..a545ec5e7 100644
--- a/lib/dpkg/db-ctrl-format.c
+++ b/lib/dpkg/db-ctrl-format.c
@@ -125,7 +125,7 @@ pkg_infodb_get_dir(void)
 }
 
 const char *
-pkg_infodb_get_file(struct pkginfo *pkg, struct pkgbin *pkgbin,
+pkg_infodb_get_file(const struct pkginfo *pkg, const struct pkgbin *pkgbin,
                     const char *filetype)
 {
        static struct varbuf vb;
diff --git a/lib/dpkg/db-ctrl.h b/lib/dpkg/db-ctrl.h
index 57f67e022..e4dccd285 100644
--- a/lib/dpkg/db-ctrl.h
+++ b/lib/dpkg/db-ctrl.h
@@ -38,7 +38,7 @@ bool pkg_infodb_is_upgrading(void);
 void pkg_infodb_upgrade(void);
 
 const char *pkg_infodb_get_dir(void);
-const char *pkg_infodb_get_file(struct pkginfo *pkg, struct pkgbin *pkgbin,
+const char *pkg_infodb_get_file(const struct pkginfo *pkg, const struct pkgbin 
*pkgbin,
                                 const char *filetype);
 const char *pkg_infodb_reset_dir(void);
 bool pkg_infodb_has_file(struct pkginfo *pkg, struct pkgbin *pkgbin,
diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c
index aa2372a64..1985df068 100644
--- a/lib/dpkg/pkg-format.c
+++ b/lib/dpkg/pkg-format.c
@@ -22,16 +22,22 @@
 #include <config.h>
 #include <compat.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include <dpkg/i18n.h>
 #include <dpkg/error.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/db-ctrl.h>
+#include <dpkg/db-fsys.h>
 #include <dpkg/parsedump.h>
 #include <dpkg/pkg-show.h>
 #include <dpkg/pkg-format.h>
@@ -279,6 +285,56 @@ virt_synopsis(struct varbuf *vb,
 }
 
 static void
+virt_fsys_last_modified(struct varbuf *vb,
+                        const struct pkginfo *pkg, const struct pkgbin *pkgbin,
+                        enum fwriteflags flags, const struct fieldinfo *fip)
+{
+       const char *listfile;
+       struct stat st;
+
+       if (pkg->status == PKG_STAT_NOTINSTALLED)
+               return;
+
+       listfile = pkg_infodb_get_file(pkg, pkgbin, LISTFILE);
+
+       if (stat(listfile, &st) < 0) {
+               if (errno == ENOENT)
+                       return;
+
+               ohshite(_("cannot get package %s filesystem last modification 
time"),
+                       pkgbin_name_const(pkg, pkgbin, pnaw_nonambig));
+       }
+
+       varbuf_printf(vb, "%ld", st.st_mtime);
+}
+
+static void
+virt_fsys_files(struct varbuf *vb,
+                const struct pkginfo *pkg, const struct pkgbin *pkgbin,
+                enum fwriteflags flags, const struct fieldinfo *fip)
+{
+       struct fsys_namenode_list *node;
+
+       /* XXX: This cast is so wrong on so many levels, but the alternatives
+        * are apparently worse. We might need to end up removing the const
+        * from the arguments.
+        *
+        * Ideally loading the entire fsys db would be cheaper, and stored
+        * in a single file, so we could do it unconditionally, before any
+        * formatting. */
+       ensure_packagefiles_available((struct pkginfo *)pkg);
+
+       if (!pkg->files_list_valid)
+               return;
+
+       for (node = pkg->files; node; node = node->next) {
+               varbuf_add_char(vb, ' ');
+               varbuf_add_str(vb, node->namenode->name);
+               varbuf_add_char(vb, '\n');
+       }
+}
+
+static void
 virt_source_package(struct varbuf *vb,
                     const struct pkginfo *pkg, const struct pkgbin *pkgbin,
                     enum fwriteflags flags, const struct fieldinfo *fip)
@@ -324,6 +380,8 @@ static const struct fieldinfo virtinfos[] = {
        { FIELD("db:Status-Want"), NULL, virt_status_want },
        { FIELD("db:Status-Status"), NULL, virt_status_status },
        { FIELD("db:Status-Eflag"), NULL, virt_status_eflag },
+       { FIELD("db-fsys:Files"), NULL, virt_fsys_files },
+       { FIELD("db-fsys:Last-Modified"), NULL, virt_fsys_last_modified },
        { FIELD("source:Package"), NULL, virt_source_package },
        { FIELD("source:Version"), NULL, virt_source_version },
        { FIELD("source:Upstream-Version"), NULL, virt_source_upstream_version 
},
diff --git a/man/dpkg-query.man b/man/dpkg-query.man
index 9963bd671..de14b9afe 100644
--- a/man/dpkg-query.man
+++ b/man/dpkg-query.man
@@ -282,6 +282,14 @@ It contains the package status word, part of the Status 
field
 It contains the package status error flag, part of the Status field
 (since dpkg 1.17.11).
 .TP
+.B db-fsys:Files
+It contains the list of the package filesystem entries separated by newlines
+(since dpkg 1.19.3).
+.TP
+.B db-fsys:Last\-Modified
+It contains the timestamp in seconds of the last time the package filesystem
+entries were modified (since dpkg 1.19.3).
+.TP
 .B source:Package
 It contains the source package name for this binary package
 (since dpkg 1.16.2).

-- 
Dpkg.Org's dpkg

Reply via email to