[PATCH 5/6] hook conffile database into dpkg unpack/configure/remove stages
in process_archive() (src/processarc.c), clean out the staged ("-new")
version of the package's conffile database.
in tarobject() (src/archives.c), some slight of hand is performed with
the backend pipe of the struct tarcontext to intercept conffiles and
place a copy in the staged ("new") conffile database for the package
before extracting it as usual.
in deferred_configure() (src/configure.c), commit the package's staged
conffile database is committed.
and finally, in checkforremoval() (src/remove.c), remove the package's
conffile database.
---
src/archives.c | 16 +++++++++++++---
src/configure.c | 4 ++++
src/processarc.c | 4 ++++
src/remove.c | 3 +++
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/archives.c b/src/archives.c
index d2a6da4..1175994 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -58,6 +58,7 @@ static security_context_t scontext = NULL;
#include "filesdb.h"
#include "main.h"
#include "archives.h"
+#include "conffiles.h"
#define MAXCONFLICTORS 20
@@ -352,7 +353,7 @@ int tarobject(struct TarInfo *ti) {
struct conffile *conff;
struct tarcontext *tc= (struct tarcontext*)ti->UserData;
- int statr, i, existingdirectory, keepexisting;
+ int statr, i, existingdirectory, keepexisting, copyfd;
ssize_t r;
struct stat stab, stabtmp;
char databuf[TARBLKSZ];
@@ -615,10 +616,19 @@ int tarobject(struct TarInfo *ti) {
}
#endif /* WITH_SELINUX */
-
+ /* 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 NormalFile0: case NormalFile1:
+ /* if the file is a conffile... */
+ if (nifd->namenode->flags & fnnf_new_conff) {
+ conff_reg_fd(tc->pkg->name, fnamevb.buf, copyfd, ti->Size);
+ copyfd = conff_get_fd(tc->pkg->name, fnamevb.buf, conff_db_new);
+ }
/* 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.
*/
@@ -629,7 +639,7 @@ int tarobject(struct TarInfo *ti) {
debug(dbg_eachfiledetail,"tarobject NormalFile[01] open size=%lu",
(unsigned long)ti->Size);
{ char fnamebuf[256];
- fd_fd_copy(tc->backendpipe, fd, ti->Size, _("backend dpkg-deb during `%.255s'"),path_quote_filename(fnamebuf,256,ti->Name));
+ fd_fd_copy(copyfd, fd, ti->Size, _("backend dpkg-deb during `%.255s'"),path_quote_filename(fnamebuf,256,ti->Name));
}
r= ti->Size % TARBLKSZ;
if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r);
diff --git a/src/configure.c b/src/configure.c
index e195362..8b7b424 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -50,6 +50,7 @@
#include <dpkg/file.h>
#include "filesdb.h"
+#include "conffiles.h"
#include "main.h"
static int conffoptcells[2][2] = {
@@ -329,6 +330,9 @@ deferred_configure(struct pkginfo *pkg)
for (conff = pkg->installed.conffiles; conff; conff = conff->next)
deferred_configure_conffile(pkg, conff);
+ /* commit the conffiles database for the new version of this package */
+ conff_commit_new(pkg->name);
+
pkg->status = stat_halfconfigured;
}
diff --git a/src/processarc.c b/src/processarc.c
index 4d2f7fe..837da7c 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -48,6 +48,7 @@
#include "filesdb.h"
#include "main.h"
#include "archives.h"
+#include "conffiles.h"
void process_archive(const char *filename) {
static const struct TarFunctions tf = {
@@ -312,6 +313,9 @@ void process_archive(const char *filename) {
* OK, we're going ahead.
*/
+ /* make sure the new conffiles dir does not exist at this point */
+ conff_db_remove(pkg->name, conff_db_new);
+
trig_activate_packageprocessing(pkg);
strcpy(cidirrest, TRIGGERSCIFILE);
trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg);
diff --git a/src/remove.c b/src/remove.c
index 44ff139..62239d3 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -42,6 +42,7 @@
#include <dpkg/myopt.h>
#include "filesdb.h"
+#include "conffiles.h"
#include "main.h"
static void checkforremoval(struct pkginfo *pkgtoremove,
@@ -490,6 +491,8 @@ static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
pop_cleanup(ehflag_normaltidy); /* closedir */
}
+ /* remove the current conffile db for this package */
+ conff_db_remove(pkg->name, conff_db_cur);
pkg->installed.conffiles = NULL;
modstatdb_note(pkg);
--
1.6.4.3
Reply to: