[Reproducible-commits] [dpkg] 44/63: dpkg-deb: Use the treewalk module to build the .deb control member

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Mar 4 17:44:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/buildinfo
in repository dpkg.

commit 513a6a9b568d3d65cc19f3caa72ce32a0af391a2
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Feb 26 10:51:57 2016 +0100

    dpkg-deb: Use the treewalk module to build the .deb control member
    
    We reduce external dependencies on commands, and get sorted file lists.
    
    Closes: #719845
---
 debian/changelog |  2 ++
 dpkg-deb/build.c | 48 +++++++++++++++++++++++++-----------------------
 2 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a684a14..a6d4c91 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -39,6 +39,8 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
     duplicate stat(2) calls, not calling find(1), and sorting the output w/o
     stalling on the entire input being slurped and sorted.
     - Use it to build the .deb data member in dpkg-deb.
+    - Use it to build the .deb control member in dpkg-deb.
+    Closes: #719845
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.
diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c
index 849f483..df9b922 100644
--- a/dpkg-deb/build.c
+++ b/dpkg-deb/build.c
@@ -54,6 +54,25 @@
 
 #include "dpkg-deb.h"
 
+static void
+control_treewalk_feed(const char *dir, int fd_out)
+{
+  struct treeroot *tree;
+  struct treenode *node;
+
+  tree = treewalk_open(dir, TREEWALK_NONE, NULL);
+  for (node = treewalk_node(tree); node; node = treewalk_next(tree)) {
+    char *nodename;
+
+    nodename = str_fmt("./%s", treenode_get_virtname(node));
+    if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0)
+      ohshite(_("failed to write filename to tar pipe (%s)"),
+              _("control member"));
+    free(nodename);
+  }
+  treewalk_close(tree);
+}
+
 /**
  * Simple structure to store information about a file.
  */
@@ -465,8 +484,7 @@ do_build(const char *const *argv)
   char *debar;
   char *tfbuf;
   int arfd;
-  int p1[2], gzfd;
-  pid_t c1, c2;
+  int gzfd;
 
   /* Decode our arguments. */
   dir = *argv++;
@@ -502,19 +520,7 @@ do_build(const char *const *argv)
   arfd = creat(debar, 0644);
   if (arfd < 0)
     ohshite(_("unable to create '%.255s'"), debar);
-  /* Fork a tar to package the control-section of the package. */
   unsetenv("TAR_OPTIONS");
-  m_pipe(p1);
-  c1 = subproc_fork();
-  if (!c1) {
-    m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
-    if (chdir(ctrldir))
-      ohshite(_("failed to chdir to '%.255s'"), ctrldir);
-    execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL);
-    ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
-  }
-  close(p1[1]);
-  free(ctrldir);
 
   /* Create a temporary file to store the control data in. Immediately
    * unlink our temporary file so others can't mess with it. */
@@ -528,7 +534,7 @@ do_build(const char *const *argv)
            tfbuf);
   free(tfbuf);
 
-  /* And run the compressor on our control archive. */
+  /* Select the compressor to use for our control archive. */
   if (opt_uniform_compression) {
     control_compress_params = compress_params;
   } else {
@@ -539,14 +545,10 @@ do_build(const char *const *argv)
       internerr("invalid control member compressor params: %s", err.str);
   }
 
-  c2 = subproc_fork();
-  if (!c2) {
-    compress_filter(&control_compress_params, p1[0], gzfd, _("compressing control member"));
-    exit(0);
-  }
-  close(p1[0]);
-  subproc_reap(c2, _("<compress> from tar -cf"), 0);
-  subproc_reap(c1, "tar -cf", 0);
+  /* Fork a tar to package the control-section of the package. */
+  tarball_pack(ctrldir, control_treewalk_feed, &control_compress_params, gzfd);
+
+  free(ctrldir);
 
   if (lseek(gzfd, 0, SEEK_SET))
     ohshite(_("failed to rewind temporary file (%s)"), _("control member"));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list