summaryrefslogtreecommitdiff
path: root/main/avahi/build-db-Use-the-same-database-format-that-the-C-code-exp.patch
blob: 76211f4c89d46d94659f8886338b9a73a5f20dbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Patch-Source: https://salsa.debian.org/utopia-team/avahi/-/blob/b1a3a539ac0b6d79a7a0b87dccbb99028e10ec63/debian/patches/build-db-Use-the-same-database-format-that-the-C-code-exp.patch
this is needed to build the python module
--
From: Simon McVittie <smcv@debian.org>
Date: Thu, 7 May 2020 12:13:56 +0100
Subject: build-db: Use the same database format that the C code expects

Otherwise, Python 2 anydbm will preferentially choose Berkeley DB format
(dbhash/bsddb), which is neither GNU gdbm nor traditional Unix (n)dbm.

Signed-off-by: Simon McVittie <smcv@debian.org>
Fixes: https://github.com/lathiat/avahi/issues/260
---
 configure.ac                      | 11 ++++++++---
 service-type-database/Makefile.am |  4 ++--
 service-type-database/build-db    | 27 +++++++++++++++++++++------
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 58db8c7..5aea4e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -871,9 +871,14 @@ if test "x$HAVE_PYTHON" = "xyes" ; then
         fi
 
         AM_CHECK_PYMOD(socket,,,[AC_MSG_ERROR(Could not find Python module socket)])
-        if test "x$HAVE_GDBM" = "xyes" || test "x$HAVE_DBM" = "xyes"; then
-            AM_CHECK_PYMOD(anydbm,,,[
-                AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
+        if test "x$HAVE_GDBM" = "xyes"; then
+            AM_CHECK_PYMOD([dbm.gnu], [], [], [
+                AM_CHECK_PYMOD([gdbm], [], [], [AC_MSG_ERROR(Could not find Python module dbm.gnu or gdbm)])
+            ])
+        fi
+        if test "x$HAVE_DBM" = "xyes"; then
+            AM_CHECK_PYMOD([dbm.ndbm], [], [], [
+                AM_CHECK_PYMOD([dbm], [], [], [AC_MSG_ERROR(Could not find Python module dbm.ndbm or dbm)])
             ])
         fi
     fi
diff --git a/service-type-database/Makefile.am b/service-type-database/Makefile.am
index f9fa082..0ead0f6 100644
--- a/service-type-database/Makefile.am
+++ b/service-type-database/Makefile.am
@@ -28,7 +28,7 @@ noinst_SCRIPTS=build-db
 pkglibdata_DATA+=service-types.db
 
 service-types.db: service-types
-	$(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
+	$(AM_V_GEN)$(PYTHON) build-db --gnu $< $@.coming && \
 	mv $@.coming $@
 
 CLEANFILES = service-types.db
@@ -44,7 +44,7 @@ service-types.db.pag: service-types.db
 service-types.db.dir: service-types.db
 	$(AM_V_GEN)mv service-types.db.coming.dir service-types.db.dir
 service-types.db: service-types build-db
-	$(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
+	$(AM_V_GEN)$(PYTHON) build-db --ndbm $< $@.coming && \
 	if test -f "$@.coming"; then mv $@.coming $@; fi
 
 CLEANFILES = service-types.db*
diff --git a/service-type-database/build-db b/service-type-database/build-db
index 78ee892..6415d27 100755
--- a/service-type-database/build-db
+++ b/service-type-database/build-db
@@ -17,13 +17,28 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 # USA.
 
-try:
-    import anydbm as dbm
-except ImportError:
-    import dbm
-
 import sys
 
+if sys.argv[1] == '--gnu':
+    if sys.version_info >= (3,):
+        import dbm.gnu as chosen_dbm
+    else:
+        import gdbm as chosen_dbm
+
+    sys.argv[1:] = sys.argv[2:]
+elif sys.argv[1] == '--ndbm':
+    if sys.version_info >= (3,):
+        import dbm.ndbm as chosen_dbm
+    else:
+        import dbm as chosen_dbm
+
+    sys.argv[1:] = sys.argv[2:]
+else:
+    if sys.version_info >= (3,):
+        import dbm as chosen_dbm
+    else:
+        import anydbm as chosen_dbm
+
 if len(sys.argv) > 1:
     infn = sys.argv[1]
 else:
@@ -34,7 +49,7 @@ if len(sys.argv) > 2:
 else:
     outfn = infn + ".db"
 
-db = dbm.open(outfn, "n")
+db = chosen_dbm.open(outfn, "n")
 
 for ln in open(infn, "r"):
     ln = ln.strip(" \r\n\t")