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=d2ec96cc99b15b97cfcecead3f2872c45a510855

commit d2ec96cc99b15b97cfcecead3f2872c45a510855
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Aug 10 02:22:39 2018 +0200

    libdpkg: Factor out package stanza printing into its own function
    
    We will then be able to use it to print the package database into
    stdout, for example.
---
 debian/changelog     |  1 +
 lib/dpkg/dpkg-db.h   |  1 +
 lib/dpkg/dump.c      | 21 +++++++++++++++------
 lib/dpkg/libdpkg.map |  1 +
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 3d949507b..4cf04b4c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -199,6 +199,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - libdpkg: Switch db-fsys to use the new file_slurp() function.
     - libdpkg: Add new pkg_infodb_reset_dir().
     - libdpkg: Add new m_dup() function.
+    - libdpkg: Factor out package stanza printing into its own function.
   * Build system:
     - Set distribution tarball format to ustar, instead of default v7 format.
     - Mark PO4A and POD2MAN as precious variables.
diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h
index a60da4a50..8f34d6682 100644
--- a/lib/dpkg/dpkg-db.h
+++ b/lib/dpkg/dpkg-db.h
@@ -436,6 +436,7 @@ enum writedb_flags {
   wdb_must_sync                        = DPKG_BIT(1),
 };
 
+void writedb_records(FILE *fp, const char *filename, enum writedb_flags flags);
 void writedb(const char *filename, enum writedb_flags flags);
 
 /* Note: The varbufs must have been initialized and will not be
diff --git a/lib/dpkg/dump.c b/lib/dpkg/dump.c
index b70023c9e..0933b6dff 100644
--- a/lib/dpkg/dump.c
+++ b/lib/dpkg/dump.c
@@ -492,7 +492,7 @@ writerecord(FILE *file, const char *filename,
 }
 
 void
-writedb(const char *filename, enum writedb_flags flags)
+writedb_records(FILE *fp, const char *filename, enum writedb_flags flags)
 {
   static char writebuf[8192];
 
@@ -500,14 +500,11 @@ writedb(const char *filename, enum writedb_flags flags)
   struct pkginfo *pkg;
   struct pkgbin *pkgbin;
   const char *which;
-  struct atomic_file *file;
   struct varbuf vb = VARBUF_INIT;
 
   which = (flags & wdb_dump_available) ? "available" : "status";
 
-  file = atomic_file_new(filename, ATOMIC_FILE_BACKUP);
-  atomic_file_open(file);
-  if (setvbuf(file->fp, writebuf, _IOFBF, sizeof(writebuf)))
+  if (setvbuf(fp, writebuf, _IOFBF, sizeof(writebuf)))
     ohshite(_("unable to set buffering on %s database file"), which);
 
   iter = pkg_db_iter_new();
@@ -519,13 +516,25 @@ writedb(const char *filename, enum writedb_flags flags)
     varbufrecord(&vb, pkg, pkgbin);
     varbuf_add_char(&vb, '\n');
     varbuf_end_str(&vb);
-    if (fputs(vb.buf, file->fp) < 0)
+    if (fputs(vb.buf, fp) < 0)
       ohshite(_("failed to write %s database record about '%.50s' to 
'%.250s'"),
               which, pkgbin_name(pkg, pkgbin, pnaw_nonambig), filename);
     varbuf_reset(&vb);
   }
   pkg_db_iter_free(iter);
   varbuf_destroy(&vb);
+}
+
+void
+writedb(const char *filename, enum writedb_flags flags)
+{
+  struct atomic_file *file;
+
+  file = atomic_file_new(filename, ATOMIC_FILE_BACKUP);
+  atomic_file_open(file);
+
+  writedb_records(file->fp, filename, flags);
+
   if (flags & wdb_must_sync)
     atomic_file_sync(file);
 
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index 2bcbc99ff..cc570f09c 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -367,6 +367,7 @@ LIBDPKG_PRIVATE {
        parsedb_parse;
        parsedb_close;
        parsedb;
+       writedb_records;
        writedb;
 
        dpkg_db_set_dir;

-- 
Dpkg.Org's dpkg

Reply via email to