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

cdebconf patches



Hi all,

Still working on cdebconf, despite being in the middle of a job change,
so here are a couple of patches I would like to sumit :

0001 fixes a trivial missing include (database.h includes a reference to
DEBCONF_MAX_CONFIGPATH_LEN, which is defined in constants.h

0002 fixes an obvious warning from my previous patch.

0003 moves the logic of loading a templates file from
debconf-loadtemplate.c into database.c, declares it in database.h, and
reuses it in dpkg-reconfigure.c instead of reproducing the almost
identical logic. The patch doesn't bring anything in itself, but this
logic will be needed in dpkg-preconfigure and debconf, so having it
shared sounds like a good idea.

Any feedback or comment would as usual be very welcome.

Regis
>From 30e7d6a838a2936264b39871a963b544f85f2987 Mon Sep 17 00:00:00 2001
From: Regis Boudin <regis@boudin.name>
Date: Mon, 23 May 2011 23:27:26 +0100
Subject: [PATCH 1/3] fix missing include

---
 src/database.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/database.h b/src/database.h
index 574bfef..c350280 100644
--- a/src/database.h
+++ b/src/database.h
@@ -7,6 +7,8 @@
 #ifndef _DATABASE_H_
 #define _DATABASE_H_
 
+#include "constants.h"
+
 /* Debconf database interfaces */
 
 struct configuration;
-- 
1.7.5.1

>From 929b37a2fb68493f8efb142b8276a76861b45bb5 Mon Sep 17 00:00:00 2001
From: Regis Boudin <regis@boudin.name>
Date: Mon, 23 May 2011 22:43:48 +0100
Subject: [PATCH 2/3] fix silly warning

---
 src/modules/db/rfc822db/rfc822db.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/modules/db/rfc822db/rfc822db.c b/src/modules/db/rfc822db/rfc822db.c
index 70da04d..4454dc7 100644
--- a/src/modules/db/rfc822db/rfc822db.c
+++ b/src/modules/db/rfc822db/rfc822db.c
@@ -130,7 +130,7 @@ static unsigned int parse_flags(char *string)
     char *wc, *owc;
    
     if (!string)
-	    return;
+	    return 0;
 
     owc = wc = strdup(string);
 
-- 
1.7.5.1

>From 4b08b448faf505ba04b509c22f997a8efb546cd5 Mon Sep 17 00:00:00 2001
From: Regis Boudin <regis@boudin.name>
Date: Fri, 20 May 2011 00:11:47 +0100
Subject: [PATCH 3/3] shared template_db_loadfile()

Merge almost common code between debconf-loadtemplate and
dpkg-reconfigure into template_db_loadfile(), which will be reused
in dpkg-preconfigure and debconf itself as well
---
 src/database.c             |   59 ++++++++++++++++++++++++++++++++++++++++++++
 src/database.h             |   12 +++++++++
 src/debconf-loadtemplate.c |   40 +++--------------------------
 src/dpkg-reconfigure.c     |   42 +------------------------------
 4 files changed, 76 insertions(+), 77 deletions(-)

diff --git a/src/database.c b/src/database.c
index 2f1c9f2..39ac5dd 100644
--- a/src/database.c
+++ b/src/database.c
@@ -208,6 +208,65 @@ void template_db_delete(struct template_db *db)
     DELETE(db);
 }
 
+/************************************************************************
+ * Function: loadtemplate
+ * Inputs: tdb - templates database
+ *         qdb - questions database
+ *         filename - which file to load templates from
+ *         owner - owner for the templates
+ * Outputs: none
+ * Description: loads all the templates from a file
+ * Assumptions: none
+ ************************************************************************/
+void template_db_loadfile(struct template_db *tdb, struct question_db *qdb, const char *filename, const char *owner, int flags)
+{
+    struct template *t, *oldt;
+    struct question *q;
+
+    if (!tdb)
+    {
+        INFO(INFO_ERROR, "Templates database not initialised");
+        return;
+    }
+
+    t = template_load(filename);
+    while (t)
+    {
+        oldt = tdb->methods.get(tdb, t->tag);
+        if (oldt == NULL || (flags & DC_LOADTEMPLATE_MERGE) == 0 || NULL == template_l10nmerge(oldt, t))
+        {
+            if (tdb->methods.set(tdb, t) != DC_OK)
+                INFO(INFO_ERROR, "Cannot add template %s", t->tag);
+        }
+        if (oldt)
+            template_deref(oldt);
+
+        if (qdb)
+        {
+            q = qdb->methods.get(qdb, t->tag);
+            if (q == NULL)
+            {
+                q = question_new(t->tag);
+                q->template = t;
+                template_ref(t);
+            }
+            else if (q->template != t)
+            {
+                template_deref(q->template);
+                q->template = t;
+                template_ref(t);
+            }
+            question_owner_add(q, owner);
+            if (qdb->methods.set(qdb, q) != DC_OK)
+                INFO(INFO_ERROR, "Cannot add question %s", t->tag);
+            question_deref(q);
+        }
+        oldt = t;
+        t = t->next;
+        template_deref(oldt);
+    }
+}
+
 /**
  *
  * Config database 
diff --git a/src/database.h b/src/database.h
index c350280..1dd027c 100644
--- a/src/database.h
+++ b/src/database.h
@@ -17,6 +17,9 @@ struct template_db;
 struct question;
 struct question_db;
 
+#define DC_LOADTEMPLATE_NONE  (0)
+#define DC_LOADTEMPLATE_MERGE (1<<0)
+
 /**
  * @brief Methods for a template database module
  */
@@ -110,6 +113,15 @@ struct template_db *template_db_new(struct configuration *cfg, const char *insta
 void template_db_delete(struct template_db *db);
 
 /**
+ * @brief Loads all the templates from a file
+ * @param tdb template database object
+ * @param qdb question database object
+ * @param filename file to load templates from
+ * @param owner owner of the templates
+ */
+void template_db_loadfile(struct template_db *tdb, struct question_db *qdb, const char *filename, const char *owner, int flagsb);
+
+/**
  * @brief Create a new question db object
  * @param cfg configuration
  * @param tdb associated template database object
diff --git a/src/debconf-loadtemplate.c b/src/debconf-loadtemplate.c
index ed1c9e1..bacb97b 100644
--- a/src/debconf-loadtemplate.c
+++ b/src/debconf-loadtemplate.c
@@ -74,9 +74,7 @@ int main(int argc, char **argv)
     struct configuration *config = NULL;
     struct question_db *qdb = NULL;
     struct template_db *tdb = NULL;
-    struct template *t = NULL;
-    struct question *q = NULL;
-    struct template *oldt = NULL;
+    int flags = 0;
     char *owner;
     int i;
 
@@ -114,41 +112,11 @@ int main(int argc, char **argv)
 
     owner = argv[optind];
     i = optind + 1;
+    if (merge)
+        flags |= DC_LOADTEMPLATE_MERGE;
     while (i < argc)
     {
-        t = template_load(argv[i++]);
-        while (t)
-        {
-            oldt = tdb->methods.get(tdb, t->tag);
-            if (oldt == NULL || merge == 0 || NULL == template_l10nmerge(oldt, t))
-            {
-                if (tdb->methods.set(tdb, t) != DC_OK)
-                    INFO(INFO_ERROR, "Cannot add template %s", t->tag);
-            }
-            if (oldt)
-                template_deref(oldt);
-
-            q = qdb->methods.get(qdb, t->tag);
-            if (q == NULL)
-            {
-                q = question_new(t->tag);
-                q->template = t;
-                template_ref(t);
-            }
-            else if (q->template != t)
-            {
-                template_deref(q->template);
-                q->template = t;
-                template_ref(t);
-            }
-            question_owner_add(q, owner);
-            if (qdb->methods.set(qdb, q) != DC_OK)
-                INFO(INFO_ERROR, "Cannot add config %s", t->tag);
-            question_deref(q);
-            oldt = t;
-            t = t->next;
-            template_deref(oldt);
-        }
+        template_db_loadfile(tdb, qdb, argv[i++], owner, flags);
     }
 
     if (tdb->methods.save(tdb) != DC_OK)
diff --git a/src/dpkg-reconfigure.c b/src/dpkg-reconfigure.c
index 023972f..e9ceff3 100644
--- a/src/dpkg-reconfigure.c
+++ b/src/dpkg-reconfigure.c
@@ -116,46 +116,6 @@ static bool file_exists(const char *filename, mode_t mode)
 }
 
 /************************************************************************
- * Function: loadtemplate
- * Inputs: filename - which file to load templates from
- *         owner - owner for the templates
- * Outputs: none
- * Description: loads all the templates from a file
- * Assumptions: none
- ************************************************************************/
-static void loadtemplate(const char *filename, const char *owner)
-{
-	struct template *t;
-	struct question *q;
-
-	t = template_load(filename);
-	while (t)
-	{
-		if (g_templates->methods.set(g_templates, t) != DC_OK)
-			INFO(INFO_ERROR, "Cannot add template %s", t->tag);
-
-		q = g_questions->methods.get(g_questions, t->tag);
-		if (q == NULL)
-		{
-			q = question_new(t->tag);
-			q->template = t;
-			template_ref(t);
-		}
-		else if (q->template != t)
-		{
-			template_deref(q->template);
-			q->template = t;
-			template_ref(t);
-		}
-		question_owner_add(q, owner);
-		if (g_questions->methods.set(g_questions, q) != DC_OK)
-			INFO(INFO_ERROR, "Cannot add question %s", t->tag);
-		question_deref(q);
-		t = t->next;
-	}
-}
-
-/************************************************************************
  * Function: getfield
  * Inputs: package - which package to get the status of
  *         field - field to get value of
@@ -388,7 +348,7 @@ static int reconfigure(char **pkgs, int i, int max)
 
 		filename = control_path(pkg, "templates");
 		if (file_exists(filename, S_IRUSR|S_IRGRP|S_IROTH))
-			loadtemplate(filename, pkg);
+			template_db_loadfile(g_templates, g_questions, filename, pkg, DC_LOADTEMPLATE_NONE);
 		free(filename);
 		
 		/* Simulation of reinstalling a package, without bothering with
-- 
1.7.5.1


Reply to: