[PATCH 4/7] Hook conffile database into dpkg unpack/configure/remove stages
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 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.
---
src/archives.c | 17 ++++++++++++++---
src/configure.c | 9 +++++++++
src/remove.c | 3 +++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/archives.c b/src/archives.c
index 2654b98..8b31a9b 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -57,6 +57,7 @@ static security_context_t scontext = NULL;
#include "filesdb.h"
#include "main.h"
#include "archives.h"
+#include "conffiledb.h"
#define MAXCONFLICTORS 20
@@ -360,7 +361,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];
@@ -623,10 +624,20 @@ 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) {
+ 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.
*/
@@ -637,7 +648,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,
+ 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 030bde3..88a7c48 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -47,6 +47,7 @@
#include <dpkg/file.h>
#include <dpkg/subproc.h>
+#include "conffiledb.h"
#include "filesdb.h"
#include "main.h"
@@ -345,6 +346,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 bf09e15..909f546 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -40,6 +40,7 @@
#include <dpkg/myopt.h>
#include "filesdb.h"
+#include "conffiledb.h"
#include "main.h"
static void checkforremoval(struct pkginfo *pkgtoremove,
@@ -488,6 +489,8 @@ 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.6.5.3
Reply to: