[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 4/7] Hook conffile database into dpkg unpack/configure/remove stages



From: Sean Finney <seanius@debian.org>
Date: Mon, 14 Dec 2009 08:27:34 +0100

In tarobject() (src/archives.c), some sleight of hand is performed with
the backend pipe of the struct tarcontext to intercept conffiles and
place a copy in the available conffile database for the package before
extracting it as usual.

In deferred_configure (src/configure.c), the conffiledb of the previous
version of a package is removed before marking configuration successful.

And finally, in removal_bulk_remove_configfiles() (src/remove.c), remove
the package's conffile database for the given version of the package when
it is being purged.

[jn: rebased

Conflicts:

	src/archives.c
	src/remove.c
]

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
This is the heart of it --- teeing each conffile to the conffiledb
when writing the corresponding .dpkg-tmp files.  Nice and clean.

 src/archives.c  |   15 ++++++++++++++-
 src/configure.c |    9 +++++++++
 src/remove.c    |    4 ++++
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/archives.c b/src/archives.c
index 9354c1e..a4926a3 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -59,6 +59,7 @@
 #endif
 
 #include "filesdb.h"
+#include "conffiledb.h"
 #include "main.h"
 #include "archives.h"
 #include "filters.h"
@@ -439,6 +440,7 @@ tarobject(void *ctx, struct tar_entry *ti)
   struct tarcontext *tc = ctx;
   bool existingdir, keepexisting;
   int statr;
+  int copyfd;
   ssize_t r;
   struct stat stab, stabtmp;
   char databuf[TARBLKSZ];
@@ -692,9 +694,20 @@ tarobject(void *ctx, struct tar_entry *ti)
    * its original filename.
    */
 
+  /* in the case of a conffile we may want to extract the file somewhere
+   * else first, thus we use a "middleman" variable to keep the code clean
+   * and generalizable
+   */
+  copyfd = tc->backendpipe;
   /* Extract whatever it is as .dpkg-new ... */
   switch (ti->type) {
   case tar_filetype_file:
+    /* if the file is a conffile... */
+    if (nifd->namenode->flags & fnnf_new_conff) {
+      conffiledb_register_new_conffile(tc->pkg, fnamevb.buf, copyfd, ti->Size);
+      copyfd = conffiledb_open_conffile(tc->pkg, &tc->pkg->available.version,
+                                        fnamevb.buf);
+    }
     /* We create the file with mode 0 to make sure nobody can do anything with
      * it until we apply the proper mode, which might be a statoverride. */
     fd= open(fnamenewvb.buf, (O_CREAT|O_EXCL|O_WRONLY), 0);
@@ -705,7 +718,7 @@ tarobject(void *ctx, struct tar_entry *ti)
     debug(dbg_eachfiledetail, "tarobject file open size=%jd",
           (intmax_t)ti->size);
     { char fnamebuf[256];
-    fd_fd_copy(tc->backendpipe, fd, ti->size,
+    fd_fd_copy(copyfd, fd, ti->size,
                _("backend dpkg-deb during `%.255s'"),
                path_quote_filename(fnamebuf, ti->name, 256));
     }
diff --git a/src/configure.c b/src/configure.c
index e0e5fe5..68decc4 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -48,6 +48,7 @@
 #include <dpkg/command.h>
 #include <dpkg/triglib.h>
 
+#include "conffiledb.h"
 #include "filesdb.h"
 #include "main.h"
 
@@ -353,6 +354,14 @@ deferred_configure(struct pkginfo *pkg)
 	                                           vdew_nonambig) : "",
 	                           NULL);
 
+	/* if we're configuring a different version from what was previously
+	 * installed (and there was something previously installed), nuke the
+	 * previous version's config files at this point */
+	if (informativeversion(&pkg->configversion) &&
+	    informativeversion(&pkg->installed.version) &&
+	    versioncompare(&pkg->configversion, &pkg->installed.version) != 0)
+		conffiledb_remove(pkg, &pkg->configversion);
+
 	pkg->eflag = eflag_ok;
 	post_postinst_tasks(pkg, stat_installed);
 }
diff --git a/src/remove.c b/src/remove.c
index 3d4879b..1efdaf3 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -42,6 +42,7 @@
 
 #include "infodb.h"
 #include "filesdb.h"
+#include "conffiledb.h"
 #include "main.h"
 
 /*
@@ -488,6 +489,9 @@ static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
       pop_cleanup(ehflag_normaltidy); /* closedir */
     }
 
+    /* remove all conffile db information for this package */
+    conffiledb_remove(pkg, NULL);
+
     pkg->installed.conffiles = NULL;
     modstatdb_note(pkg);
 
-- 
1.7.5.1


Reply to: