[packages/rpm] - replaced hackish trigger with a simple program that tests if BDB version has changed directly in

baggins baggins at pld-linux.org
Wed Sep 19 14:22:50 CEST 2012


commit 91ee86a9ffd2451553d65a0e1b419aafb07d38d9
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Wed Sep 19 14:21:37 2012 +0200

    - replaced hackish trigger with a simple program that tests if BDB
      version has changed directly in posttrans
    - rel 0.20

 rpm.spec             | 19 +++++++----
 rpmdb_checkversion.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 7 deletions(-)
---
diff --git a/rpm.spec b/rpm.spec
index 72a8783..b614db3 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -43,7 +43,7 @@ Summary(ru.UTF-8):	Менеджер пакетов от RPM
 Summary(uk.UTF-8):	Менеджер пакетів від RPM
 Name:		rpm
 Version:	5.4.10
-Release:	0.19
+Release:	0.20
 License:	LGPL
 Group:		Base
 # http://rpm5.org/files/rpm/rpm-5.4/rpm-5.4.10-0.20120706.src.rpm
@@ -78,6 +78,7 @@ Source22:	rpm.noautoreq
 Source23:	rpm.noautoreqdep
 Source24:	rpm.noautoreqfiles
 Source25:	%{name}-php-requires.php
+Source26:	rpmdb_checkversion.c
 Patch0:		%{name}-branch.patch
 Patch1:		%{name}-man_pl.patch
 Patch2:		%{name}-popt-aliases.patch
@@ -846,6 +847,8 @@ install %{SOURCE11} scripts/perl.prov.in
 # generate Group translations to *.po
 awk -f %{SOURCE6} %{SOURCE1}
 
+install %{SOURCE26} tools/rpmdb_checkversion.c
+
 %build
 %{__libtoolize}
 #%{__autopoint}
@@ -902,6 +905,8 @@ sed -i \
 
 %{?with_apidocs:%{__make} apidocs}
 
+%{__cc} %{rpmcflags} tools/rpmdb_checkversion.c -o tools/rpmdb_checkversion -ldb
+
 %install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{/bin,/%{_lib},/etc/sysconfig,%{_sysconfdir}/rpm} \
@@ -1062,6 +1067,8 @@ touch $RPM_BUILD_ROOT%{_sysconfdir}/rpm/sysinfo/Obsoletename
 touch $RPM_BUILD_ROOT%{_sysconfdir}/rpm/sysinfo/Providename
 touch $RPM_BUILD_ROOT%{_sysconfdir}/rpm/sysinfo/Requirename
 
+install tools/rpmdb_checkversion $RPM_BUILD_ROOT%{_rpmlibdir}/bin
+
 # create macro loading wrappers for backward compatibility
 for m in gstreamer java mono perl php python; do
 	echo "%%{load:%{_rpmlibdir}/macros.d/$m}" >$RPM_BUILD_ROOT%{_rpmlibdir}/macros.$m
@@ -1114,14 +1121,11 @@ if [ -f %{_sysconfdir}/rpm/sysinfo ]; then
 fi
 
 %posttrans
-if [ -e /var/lib/rpm/__convert_needed ]; then
-	%{_rpmlibdir}/bin/dbconvert --rebuilddb
-	%{__rm} -f /var/lib/rpm/__convert_needed
+if [ -x %{_rpmlibdir}/bin/rpmdb_checkversion ] && \
+		! %{_rpmlibdir}/bin/rpmdb_checkversion -h /var/lib/rpm -d /var/lib/rpm ; then
+	[ -x %{_rpmlibdir}/bin/dbconvert ] && %{_rpmlibdir}/bin/dbconvert --rebuilddb
 fi
 
-%triggerpostun -- %{name} < 5.4.0-1
-:>/var/lib/rpm/__convert_needed
-
 %triggerpostun -- %{name} < 4.4.9-44
 %{_rpmlibdir}/hrmib-cache
 
@@ -1177,6 +1181,7 @@ find %{_rpmlibdir} -name '*-linux' -type l | xargs rm -f
 
 %dir %{_rpmlibdir}/bin
 %attr(755,root,root) %{_rpmlibdir}/bin/dbconvert
+%attr(755,root,root) %{_rpmlibdir}/bin/rpmdb_checkversion
 
 %files base
 %defattr(644,root,root,755)
diff --git a/rpmdb_checkversion.c b/rpmdb_checkversion.c
new file mode 100644
index 0000000..f85a4a7
--- /dev/null
+++ b/rpmdb_checkversion.c
@@ -0,0 +1,93 @@
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <db.h>
+
+const char *progname = "rpmdb_checkversion";		/* Program name. */
+
+/*
+ * A very simple program to check for a Berkeley DB environment mismatch.
+ */
+int
+main(int argc, char *argv[])
+{
+	extern char *optarg;
+	extern int optind;
+	const char *data_dir, *home;
+	int ch, quiet;
+	DB_ENV *dbenv;
+	int ret;
+
+	/*
+	 * All of the shared database files live in home, but
+	 * data files will live in data_dir.
+	 */
+	quiet = 0;
+	home = "/var/lib/rpm";
+	data_dir = "/var/lib/rpm";
+	while ((ch = getopt(argc, argv, "h:d:q")) != EOF)
+		switch (ch) {
+		case 'h':
+			home = optarg;
+			break;
+		case 'd':
+			data_dir = optarg;
+			break;
+		case 'q':
+			quiet = 1;
+			break;
+		case '?':
+		default:
+			(void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
+			return (0);
+		}
+	argc -= optind;
+	argv += optind;
+
+	if (argc != 0) {
+		(void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
+		return (0);
+	}
+
+	/*
+	 * Create an environment object and initialize it for error
+	 * reporting.
+	 */
+	if ((ret = db_env_create(&dbenv, 0)) != 0) {
+		if (!quiet)
+			fprintf(stderr, "%s: %s\n", progname, db_strerror(ret));
+		return (0);
+	}
+	if (quiet) {
+		dbenv->set_errfile(dbenv, NULL);
+	} else {
+		dbenv->set_errfile(dbenv, stderr);
+	}
+	dbenv->set_errpfx(dbenv, progname);
+
+	/*
+	 * We want to specify the shared memory buffer pool cachesize,
+	 * but everything else is the default.
+	 */
+	if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0) {
+		dbenv->err(dbenv, ret, "set_cachesize");
+		dbenv->close(dbenv, 0);
+		return (0);
+	}
+
+	/* Databases are in a subdirectory. */
+	(void)dbenv->set_data_dir(dbenv, data_dir);
+
+	/* Open the environment with full transactional support. */
+	ret = dbenv->open(dbenv, home, DB_INIT_MPOOL, 0644);
+	/* Close the environment handle. */
+	dbenv->close(dbenv, 0);
+
+	if (ret == DB_VERSION_MISMATCH) {
+		return (1);
+	}
+
+	return (0);
+}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm.git/commitdiff/91ee86a9ffd2451553d65a0e1b419aafb07d38d9



More information about the pld-cvs-commit mailing list