[packages/rpm/rpm.org] - set defaut backend to sqlite

baggins baggins at pld-linux.org
Tue Jan 5 23:20:35 CET 2021


commit 269352f06cca35124b933a3d94d3b91ae05a75f4
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Tue Jan 5 23:19:57 2021 +0100

    - set defaut backend to sqlite

 dbupgrade.sh            |  40 --------
 rpm.spec                |  58 +++++------
 rpmdb_checkversion.c    | 121 -----------------------
 rpmdb_reset.c           | 248 ------------------------------------------------
 sqlite-db-backend.patch |  11 +++
 5 files changed, 36 insertions(+), 442 deletions(-)
---
diff --git a/rpm.spec b/rpm.spec
index 60378b9..ffb5a73 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -26,7 +26,7 @@ Summary(ru.UTF-8):	Менеджер пакетов от RPM
 Summary(uk.UTF-8):	Менеджер пакетів від RPM
 Name:		rpm
 Version:	4.16.1.2
-Release:	0.1
+Release:	0.2
 Epoch:		1
 License:	GPL v2 / LGPL v2.1
 Group:		Base
@@ -48,9 +48,6 @@ Source12:	%{name}.noautoprovfiles
 Source13:	%{name}.noautoreq
 Source14:	%{name}.noautoreqfiles
 Source15:	perl.prov
-Source16:	%{name}db_checkversion.c
-Source17:	%{name}db_reset.c
-Source18:	dbupgrade.sh
 Patch0:		%{name}-man_pl.patch
 Patch1:		%{name}-popt-aliases.patch
 Patch2:		%{name}-perl-macros.patch
@@ -83,6 +80,7 @@ Patch29:	%{name}-noarch_py_prov.patch
 Patch30:	missing-ghost-terminate-build.patch
 Patch31:	missing-doc-terminate-build.patch
 Patch32:	noexpand.patch
+Patch33:	sqlite-db-backend.patch
 URL:		https://rpm.org/
 BuildRequires:	acl-devel
 BuildRequires:	db-devel >= %{db_ver}
@@ -580,6 +578,7 @@ Dokumentacja API RPM-a oraz przewodniki w formacie HTML generowane ze
 %patch30 -p1
 %patch31 -p1
 %patch32 -p1
+%patch33 -p1
 
 install %{SOURCE15} scripts/perl.prov.in
 
@@ -588,9 +587,6 @@ install %{SOURCE15} scripts/perl.prov.in
 # generate Group translations to *.po
 awk -f %{SOURCE6} %{SOURCE5}
 
-install %{SOURCE16} tools/rpmdb_checkversion.c
-install %{SOURCE17} tools/rpmdb_reset.c
-
 %{__sed} -i -e '1s,/usr/bin/python,%{__python3},' scripts/pythondistdeps.py
 
 %build
@@ -634,18 +630,6 @@ sed -i \
 
 %{__make}
 
-%{__cc} %{rpmcflags} tools/rpmdb_checkversion.c -o tools/rpmdb_checkversion -ldb
-%{__cc} %{rpmcflags} tools/rpmdb_reset.c -o tools/rpmdb_reset -ldb
-
-if tools/rpmdb_checkversion -V 2>&1 | grep "t match library version"; then
-	echo "Error linking rpmdb tools!"
-	exit 1
-fi
-if tools/rpmdb_reset -V 2>&1 | grep "t match library version"; then
-	echo "Error linking rpmdb tools!"
-	exit 1
-fi
-
 %if %{with python3}
 cd python
 %py3_build
@@ -732,10 +716,6 @@ cp -p %{SOURCE12} $RPM_BUILD_ROOT%{_sysconfdir}/rpm/noautoprovfiles
 cp -p %{SOURCE13} $RPM_BUILD_ROOT%{_sysconfdir}/rpm/noautoreq
 cp -p %{SOURCE14} $RPM_BUILD_ROOT%{_sysconfdir}/rpm/noautoreqfiles
 
-cp -p tools/rpmdb_checkversion $RPM_BUILD_ROOT%{_rpmlibdir}/
-cp -p tools/rpmdb_reset $RPM_BUILD_ROOT%{_rpmlibdir}/
-cp -p %{SOURCE18} $RPM_BUILD_ROOT%{_rpmlibdir}/dbupgrade.sh
-
 # move rpm to /bin
 %{__mv} $RPM_BUILD_ROOT%{_bindir}/rpm $RPM_BUILD_ROOT/bin
 ln -sf /bin/rpm $RPM_BUILD_ROOT%{_bindir}/rpmquery
@@ -747,10 +727,16 @@ for a in librpm.so librpmbuild.so librpmio.so librpmsign.so; do
 	ln -sf /%{_lib}/$(basename $RPM_BUILD_ROOT/%{_lib}/${a}.*.*.*) $RPM_BUILD_ROOT%{_libdir}/${a}
 done
 
-#./rpmdb --macros=macros --rcfile=rpmrc --dbpath=/home/users/baggins/devel/PLD/rpm/BUILD/rpm-4.15.1/x/ --initdb
-
-# Make sure we have bdb set a default backend
-grep -qE "db_backend[[:blank:]]+bdb" $RPM_BUILD_ROOT%{_rpmlibdir}/macros
+# init an empty database for %ghost'ing for all supported backends
+for be in sqlite bdb ndb; do
+	./rpmdb \
+		--macros=$RPM_BUILD_ROOT%{_rpmlibdir}/macros \
+		--rcfile=$RPM_BUILD_ROOT%{_rpmlibdir}/rpmrc \
+		--dbpath=${PWD}/${be} \
+		--define "_db_backend ${be}" \
+		--initdb
+	cp -va ${be}/. $RPM_BUILD_ROOT/var/lib/rpm/
+done
 
 %if %{with python3}
 # Remove anything that rpm make install might put there
@@ -771,8 +757,7 @@ cd ..
 rm -rf $RPM_BUILD_ROOT
 
 %posttrans
-if [ -e /var/lib/rpm/Packages ] && \
-		! %{_rpmlibdir}/rpmdb_checkversion -h /var/lib/rpm -d /var/lib/rpm; then
+if [ -e /var/lib/rpm/Packages ]; then
 	if [ ! -e /var/lib/rpm.rpmbackup-%{version}-%{release} ] && \
 			/bin/cp -a /var/lib/rpm /var/lib/rpm.rpmbackup-%{version}-%{release}; then
 		echo
@@ -783,7 +768,15 @@ if [ -e /var/lib/rpm/Packages ] && \
 	echo 'If poldek aborts after migration with rpmdb error, this is expected behaviour,'
 	echo 'you should ignore it and restart poldek'
 	echo
-	%{_rpmlibdir}/dbupgrade.sh
+	%{__rm} -rf /var/lib/rpm/log >/dev/null 2>/dev/null || :
+	%{__rm} -rf /var/lib/rpm/tmp >/dev/null 2>/dev/null || :
+	if ! /usr/bin/rpmdb --rebuilddb; then
+		echo
+		echo "rpm database conversion failed!"
+		echo "You have to run '/usr/bin/rpmdb --rebuilddb' manually"
+		echo
+		exit 1
+	fi
 fi
 
 %post	lib -p /sbin/ldconfig
@@ -823,6 +816,8 @@ find %{_rpmlibdir} -name '*-linux' -type l | xargs rm -f
 %lang(sk) %{_mandir}/sk/man8/rpm.8*
 
 %dir /var/lib/rpm
+%ghost %config(missingok,noreplace) /var/lib/rpm/*
+%ghost /var/lib/rpm/.*.lock
 
 %{_rpmlibdir}/rpmpopt*
 %{_rpmlibdir}/rpmrc
@@ -866,9 +861,6 @@ find %{_rpmlibdir} -name '*-linux' -type l | xargs rm -f
 
 %dir %{_rpmlibdir}/pld
 
-%attr(755,root,root) %{_rpmlibdir}/dbupgrade.sh
-%attr(755,root,root) %{_rpmlibdir}/rpmdb_checkversion
-%attr(755,root,root) %{_rpmlibdir}/rpmdb_reset
 %attr(755,root,root) %{_rpmlibdir}/rpmdb_dump
 %attr(755,root,root) %{_rpmlibdir}/rpmdb_load
 
diff --git a/dbupgrade.sh b/dbupgrade.sh
deleted file mode 100755
index 575aeb2..0000000
--- a/dbupgrade.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-
-ROOTDIR=
-if [ "$1" = "-r" ]; then
-	shift
-	ROOTDIR="$1"
-
-	if [ ! -d "$ROOTDIR" ]; then
-		echo "Specified root directory ($ROOTDIR) does not exist!"
-		echo "Bailing out!"
-		exit
-	fi
-fi
-
-if [ -f "$ROOTDIR"/var/lib/rpm/Packages ]; then
-	if ! /usr/lib/rpm/rpmdb_reset -r lsn "$ROOTDIR"/var/lib/rpm/Packages ; then
-		echo
-		echo "rpm database conversion failed!"
-		echo
-		echo "You have to run:"
-		echo
-		echo "	/usr/lib/rpm/rpmdb_reset -r lsn /var/lib/rpm/Packages"
-		echo "	/bin/rm -f /var/lib/rpm/__db.00*"
-		echo "	/bin/rm -rf /var/lib/rpm/log"
-		echo "	/usr/bin/rpmdb --rebuilddb"
-		echo
-		exit
-	fi
-
-	/bin/rm --interactive=never -f "$ROOTDIR"/var/lib/rpm/__db.00* >/dev/null 2>/dev/null || :
-	/bin/rm --interactive=never -rf "$ROOTDIR"/var/lib/rpm/log >/dev/null 2>/dev/null || :
-	/bin/rm --interactive=never -rf "$ROOTDIR"/var/lib/rpm/tmp >/dev/null 2>/dev/null || :
-fi
-
-if ! /usr/bin/rpmdb --rebuilddb ${ROOTDIR:+--root="$ROOTDIR"}; then
-	echo
-	echo "rpm database conversion failed!"
-	echo "You have to run /usr/bin/rpmdb manually"
-	echo
-fi
diff --git a/rpmdb_checkversion.c b/rpmdb_checkversion.c
deleted file mode 100644
index 58a169c..0000000
--- a/rpmdb_checkversion.c
+++ /dev/null
@@ -1,121 +0,0 @@
-#include <sys/types.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <db.h>
-
-int	version_check __P((void));
-
-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;
-
-	if ((ret = version_check()) != 0)
-		return (EXIT_FAILURE);
-
-	/*
-	 * 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:qV")) != EOF)
-		switch (ch) {
-		case 'h':
-			home = optarg;
-			break;
-		case 'd':
-			data_dir = optarg;
-			break;
-		case 'q':
-			quiet = 1;
-			break;
-		case 'V':
-			printf("%s\n", db_version(NULL, NULL, NULL));
-			return (EXIT_SUCCESS);
-		case '?':
-		default:
-			(void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
-			return (1);
-		}
-	argc -= optind;
-	argv += optind;
-
-	if (argc != 0) {
-		(void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
-		return (1);
-	}
-
-	/*
-	 * 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 (1);
-	}
-	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 (1);
-	}
-
-	/* 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 0
-	if (ret == DB_VERSION_MISMATCH) {
-#else
-	if (ret != 0) {
-#endif
-		return (1);
-	}
-
-	return (0);
-}
-
-int
-version_check()
-{
-	int v_major, v_minor, v_patch;
-
-	/* Make sure we're loaded with the right version of the DB library. */
-	(void)db_version(&v_major, &v_minor, &v_patch);
-	if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
-		fprintf(stderr,
-		    "%s: version %d.%d doesn't match library version %d.%d\n",
-		    progname, DB_VERSION_MAJOR,
-		    DB_VERSION_MINOR, v_major, v_minor);
-		return (EXIT_FAILURE);
-	}
-	return (0);
-}
diff --git a/rpmdb_reset.c b/rpmdb_reset.c
deleted file mode 100644
index 431d7cb..0000000
--- a/rpmdb_reset.c
+++ /dev/null
@@ -1,248 +0,0 @@
-#include <sys/types.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <db.h>
-
-typedef struct {			/* XXX: Globals. */
-	const char *progname;		/* Program name. */
-	char	*hdrbuf;		/* Input file header. */
-	u_long	lineno;			/* Input file line number. */
-	u_long	origline;		/* Original file line number. */
-	int	endodata;		/* Reached the end of a database. */
-	int	endofile;		/* Reached the end of the input. */
-	int	version;		/* Input version. */
-	char	*home;			/* Env home. */
-	char	*passwd;		/* Env passwd. */
-	int	private;		/* Private env. */
-	u_int32_t cache;		/* Env cache size. */
-} LDG;
-
-int	db_init __P((DB_ENV *, char *, u_int32_t, int *));
-int	env_create __P((DB_ENV **, LDG *));
-int	main __P((int, char *[]));
-int	usage __P((void));
-int	version_check __P((void));
-
-const char *progname = "rpmdb_reset";
-
-int
-main(argc, argv)
-	int argc;
-	char *argv[];
-{
-	enum { NOTSET, FILEID_RESET, LSN_RESET, STANDARD_LOAD } mode;
-	extern char *optarg;
-	extern int optind;
-	DBTYPE dbtype;
-	DB_ENV	*dbenv;
-	LDG ldg;
-	u_int ldf;
-	int ch, exitval, ret;
-
-	if ((exitval = version_check()) != 0)
-		goto done;
-
-	ldg.progname = progname;
-	ldg.lineno = 0;
-	ldg.endodata = ldg.endofile = 0;
-	ldg.version = 1;
-	ldg.cache = (1024 * 1024);
-	ldg.hdrbuf = NULL;
-	ldg.home = NULL;
-	ldg.passwd = NULL;
-
-	mode = NOTSET;
-	ldf = 0;
-	exitval = 0;
-	dbtype = DB_UNKNOWN;
-
-	/*
-	 * There are two modes for db_load: -r and everything else.  The -r
-	 * option zeroes out the database LSN's or resets the file ID, it
-	 * doesn't really "load" a new database.  The functionality is in
-	 * db_load because we don't have a better place to put it, and we
-	 * don't want to create a new utility for just that functionality.
-	 */
-	while ((ch = getopt(argc, argv, "h:r:V")) != EOF)
-		switch (ch) {
-		case 'h':
-			ldg.home = optarg;
-			break;
-		case 'r':
-			if (strcmp(optarg, "lsn") == 0)
-				mode = LSN_RESET;
-			else if (strcmp(optarg, "fileid") == 0)
-				mode = FILEID_RESET;
-			else {
-				exitval = usage();
-				goto done;
-			}
-			break;
-		case 'V':
-			printf("%s\n", db_version(NULL, NULL, NULL));
-			return (EXIT_SUCCESS);
-		case '?':
-		default:
-			exitval = usage();
-			goto done;
-		}
-	argc -= optind;
-	argv += optind;
-
-	if (argc != 1 || mode == NOTSET) {
-		exitval = usage();
-		goto done;
-	}
-
-	/*
-	 * Create an environment object initialized for error reporting, and
-	 * then open it.
-	 */
-	if (env_create(&dbenv, &ldg) != 0)
-		goto err;
-
-	/* If we're resetting the LSNs, that's an entirely separate path. */
-	switch (mode) {
-	case FILEID_RESET:
-		exitval = dbenv->fileid_reset(dbenv, argv[0], 0);
-		break;
-	case LSN_RESET:
-		exitval = dbenv->lsn_reset(dbenv, argv[0], 0);
-		break;
-	case NOTSET:
-		break;
-	}
-
-	if (0) {
-err:		exitval = 1;
-	}
-	if ((ret = dbenv->close(dbenv, 0)) != 0) {
-		exitval = 1;
-		fprintf(stderr,
-		    "%s: dbenv->close: %s\n", ldg.progname, db_strerror(ret));
-	}
-
-	if (ldg.passwd != NULL)
-		free(ldg.passwd);
-
-done:
-	return (exitval);
-}
-
-/*
- * env_create --
- *	Create the environment and initialize it for error reporting.
- */
-int
-env_create(dbenvp, ldg)
-	DB_ENV **dbenvp;
-	LDG *ldg;
-{
-	DB_ENV *dbenv;
-	int ret;
-
-	if ((ret = db_env_create(dbenvp, 0)) != 0) {
-		fprintf(stderr, "%s: db_env_create: %s\n",
-		    ldg->progname, db_strerror(ret));
-		return (ret);
-	}
-	dbenv = *dbenvp;
-	dbenv->set_errfile(dbenv, stderr);
-	dbenv->set_errpfx(dbenv, ldg->progname);
-	if (ldg->passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
-	    ldg->passwd, DB_ENCRYPT_AES)) != 0) {
-		dbenv->err(dbenv, ret, "set_passwd");
-		return (ret);
-	}
-	if ((ret = db_init(dbenv, ldg->home, ldg->cache, &ldg->private)) != 0)
-		return (ret);
-	dbenv->app_private = ldg;
-
-	return (0);
-}
-
-/*
- * db_init --
- *	Initialize the environment.
- */
-int
-db_init(dbenv, home, cache, is_private)
-	DB_ENV *dbenv;
-	char *home;
-	u_int32_t cache;
-	int *is_private;
-{
-	u_int32_t flags;
-	int ret;
-
-	*is_private = 0;
-	/* We may be loading into a live environment.  Try and join. */
-	flags = DB_USE_ENVIRON |
-	    DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN;
-	if ((ret = dbenv->open(dbenv, home, flags, 0)) == 0)
-		return (0);
-	if (ret == DB_VERSION_MISMATCH)
-		goto err;
-
-	/*
-	 * We're trying to load a database.
-	 *
-	 * An environment is required because we may be trying to look at
-	 * databases in directories other than the current one.  We could
-	 * avoid using an environment iff the -h option wasn't specified,
-	 * but that seems like more work than it's worth.
-	 *
-	 * No environment exists (or, at least no environment that includes
-	 * an mpool region exists).  Create one, but make it private so that
-	 * no files are actually created.
-	 */
-#define	LF_SET(f)	((flags) |= (f))
-#define	LF_CLR(f)	((flags) &= ~(f))
-	LF_CLR(DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN);
-	LF_SET(DB_CREATE | DB_PRIVATE);
-	*is_private = 1;
-	if ((ret = dbenv->set_cachesize(dbenv, 0, cache, 1)) != 0) {
-		dbenv->err(dbenv, ret, "set_cachesize");
-		return (1);
-	}
-	if ((ret = dbenv->open(dbenv, home, flags, 0)) == 0)
-		return (0);
-
-	/* An environment is required. */
-err:	dbenv->err(dbenv, ret, "DB_ENV->open");
-	return (1);
-}
-
-/*
- * usage --
- *	Display the usage message.
- */
-int
-usage()
-{
-	(void)fprintf(stderr, "usage: %s %s\n\t%s %s\n",
-	    progname, "[-V]",
-	    progname, "-r lsn | fileid [-h home] db_file");
-	return (EXIT_FAILURE);
-}
-
-int
-version_check()
-{
-	int v_major, v_minor, v_patch;
-
-	/* Make sure we're loaded with the right version of the DB library. */
-	(void)db_version(&v_major, &v_minor, &v_patch);
-	if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
-		fprintf(stderr,
-		    "%s: version %d.%d doesn't match library version %d.%d\n",
-		    progname, DB_VERSION_MAJOR,
-		    DB_VERSION_MINOR, v_major, v_minor);
-		return (EXIT_FAILURE);
-	}
-	return (0);
-}
diff --git a/sqlite-db-backend.patch b/sqlite-db-backend.patch
new file mode 100644
index 0000000..12b4160
--- /dev/null
+++ b/sqlite-db-backend.patch
@@ -0,0 +1,11 @@
+--- rpm-4.16.1.2/macros.in~	2020-12-25 11:29:20.000000000 +0100
++++ rpm-4.16.1.2/macros.in	2021-01-05 22:55:49.955934996 +0100
+@@ -627,7 +627,7 @@
+ # sqlite Sqlite database
+ # dummy dummy backend (no actual functionality)
+ #
+-%_db_backend	      bdb
++%_db_backend	      sqlite
+ 
+ #
+ #	Macros used to configure Berkley db parameters.
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm.git/commitdiff/269352f06cca35124b933a3d94d3b91ae05a75f4



More information about the pld-cvs-commit mailing list