public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Neal Gompa <ngompa@fedoraproject.org>
To: git-commits@fedoraproject.org
Subject: [rpms/rpm] pmatilai-v6: Migrate rpmdb to /usr/lib/sysimage/rpm (#2042099)
Date: Mon, 23 Nov 2026 09:34:07 GMT	[thread overview]
Message-ID: <179542644771.1.4238654513481584042.rpms-rpm-0b9f813cd529@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : rpms/rpm
            Branch : pmatilai-v6
            Commit : 0b9f813cd529a1fc7c1336e62d82b90c81f517f1
            Author : Neal Gompa <ngompa@fedoraproject.org>
            Date   : 2022-01-26T20:14:39-05:00
            Stats  : +113/-13 in 5 file(s)
            URL    : https://src.fedoraproject.org/rpms/rpm/c/0b9f813cd529a1fc7c1336e62d82b90c81f517f1?branch=pmatilai-v6

            Log:
            Migrate rpmdb to /usr/lib/sysimage/rpm (#2042099)

Reference:  https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr

---
diff --git a/rpm-4.17.x-rpm_dbpath.patch b/rpm-4.17.x-rpm_dbpath.patch
new file mode 100644
index 0000000..b1dff4d
--- /dev/null
+++ b/rpm-4.17.x-rpm_dbpath.patch
@@ -0,0 +1,12 @@
+diff '--color=auto' -rup rpm-4.17.0-orig/macros.in rpm-4.17.0/macros.in
+--- rpm-4.17.0-orig/macros.in	2021-08-20 04:44:56.264259007 -0400
++++ rpm-4.17.0/macros.in	2022-01-26 20:11:26.864195884 -0500
+@@ -140,7 +140,7 @@
+ %_buildshell		/bin/sh
+ 
+ #	The location of the rpm database file(s).
+-%_dbpath		%{_var}/lib/rpm
++%_dbpath		%{_usr}/lib/sysimage/rpm
+ 
+ #	The location of the rpm database file(s) after "rpm --rebuilddb".
+ %_dbpath_rebuild	%{_dbpath}

diff --git a/rpm.spec b/rpm.spec
index af9c290..3cc2a04 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -30,7 +30,7 @@
 
 %global rpmver 4.17.0
 #global snapver rc1
-%global baserelease 6
+%global baserelease 7
 %global sover 9
 
 %global srcver %{rpmver}%{?snapver:-%{snapver}}
@@ -45,6 +45,11 @@ Source0: http://ftp.rpm.org/releases/%{srcdir}/rpm-%{srcver}.tar.bz2
 
 Source10: rpmdb-rebuild.service
 
+Source20: rpmdb-migrate.service
+Source21: rpmdb_migrate
+
+# Set rpmdb path to /usr/lib/sysimage/rpm
+Patch0: rpm-4.17.x-rpm_dbpath.patch
 # Disable autoconf config.site processing (#962837)
 Patch1: rpm-4.17.x-siteconfig.patch
 # In current Fedora, man-pages pkg owns all the localized man directories
@@ -377,6 +382,10 @@ popd
 
 mkdir -p $RPM_BUILD_ROOT%{_unitdir}
 install -m 644 %{SOURCE10} $RPM_BUILD_ROOT/%{_unitdir}
+install -m 644 %{SOURCE20} $RPM_BUILD_ROOT/%{_unitdir}
+
+mkdir -p $RPM_BUILD_ROOT%{rpmhome}
+install -m 755 %{SOURCE21} $RPM_BUILD_ROOT/%{rpmhome}
 
 # Save list of packages through cron
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/cron.daily
@@ -387,12 +396,12 @@ install -m 644 scripts/rpm.log ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/rpm
 
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rpm
 mkdir -p $RPM_BUILD_ROOT%{rpmhome}/macros.d
-mkdir -p $RPM_BUILD_ROOT/var/lib/rpm
+mkdir -p $RPM_BUILD_ROOT/usr/lib/sysimage/rpm
 
 # init an empty database for %ghost'ing for all supported backends
 for be in %{?with_ndb:ndb} %{?with_sqlite:sqlite}; do
     ./rpmdb --define "_db_backend ${be}" --dbpath=${PWD}/${be} --initdb
-    cp -va ${be}/. $RPM_BUILD_ROOT/var/lib/rpm/
+    cp -va ${be}/. $RPM_BUILD_ROOT/usr/lib/sysimage/rpm/
 done
 
 # some packages invoke find-debuginfo directly, preserve compat for now
@@ -414,16 +423,32 @@ make check TESTSUITEFLAGS=-j%{_smp_build_ncpus} || (cat tests/rpmtests.log; exit
 make clean
 %endif
 
+%pre
+# Symlink all rpmdb files to the new location if we're still using /var/lib/rpm
+if [ -d /var/lib/rpm ]; then
+    mkdir -p /usr/lib/sysimage/rpm
+    rpmdb_files=$(find /var/lib/rpm -maxdepth 1 -type f | sed 's|^/var/lib/rpm/||g' | sort)
+    for rpmdb_file in ${rpmdb_files[@]}; do
+        ln -sfr /var/lib/rpm/${rpmdb_file} /usr/lib/sysimage/rpm/${rpmdb_file}
+    done
+fi
+
+%triggerun -- rpm < 4.15.90-0.git14971.10
 # Handle rpmdb rebuild service on erasure of old to avoid ordering issues
 # https://pagure.io/fesco/issue/2382
-%triggerun -- rpm < 4.15.90-0.git14971.10
 if [ -x /usr/bin/systemctl ]; then
     systemctl --no-reload preset rpmdb-rebuild ||:
 fi
 
+%triggerun -- rpm < 4.17.0-7
+# Handle rpmdb migrate service on erasure of old to avoid ordering issues
+if [ -x /usr/bin/systemctl ]; then
+    systemctl --no-reload preset rpmdb-migrate ||:
+fi
+
 %posttrans
-if [ -f /var/lib/rpm/Packages ]; then
-    touch /var/lib/rpm/.rebuilddb
+if [ -d /var/lib/rpm ]; then
+    touch /var/lib/rpm/.migratedb
 fi
 
 %files -f rpm.lang
@@ -431,12 +456,13 @@ fi
 %doc CREDITS docs/manual/[a-z]*
 
 %{_unitdir}/rpmdb-rebuild.service
+%{_unitdir}/rpmdb-migrate.service
 
 %dir %{_sysconfdir}/rpm
 
-%attr(0755, root, root) %dir /var/lib/rpm
-%attr(0644, root, root) %ghost %config(missingok,noreplace) /var/lib/rpm/*
-%attr(0644, root, root) %ghost /var/lib/rpm/.*.lock
+%attr(0755, root, root) %dir /usr/lib/sysimage/rpm
+%attr(0644, root, root) %ghost %config(missingok,noreplace) /usr/lib/sysimage/rpm/*
+%attr(0644, root, root) %ghost /usr/lib/sysimage/rpm/.*.lock
 
 %{_bindir}/rpm
 %{_bindir}/rpm2archive
@@ -580,6 +606,10 @@ fi
 %doc docs/librpm/html/*
 
 %changelog
+* Wed Jan 26 2022 Neal Gompa <ngompa@fedoraproject.org> - 4.17.0-7
+- Migrate rpmdb to /usr/lib/sysimage/rpm (#2042099)
+  https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
+
 * Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 4.17.0-6
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
 

diff --git a/rpmdb-migrate.service b/rpmdb-migrate.service
new file mode 100644
index 0000000..54a934d
--- /dev/null
+++ b/rpmdb-migrate.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=RPM database migration to /usr
+ConditionPathExists=/var/lib/rpm/.migratedb
+
+# This should run before any daemons that may open the rpmdb
+DefaultDependencies=no
+After=sysinit.target
+Before=basic.target shutdown.target
+Conflicts=shutdown.target
+# In case /var is remote-mounted
+RequiresMountsFor=/var
+
+[Service]
+Type=oneshot
+ExecStart=/usr/lib/rpm/rpmdb_migrate
+
+[Install]
+WantedBy=basic.target

diff --git a/rpmdb-rebuild.service b/rpmdb-rebuild.service
index 0580adb..4cd2f33 100644
--- a/rpmdb-rebuild.service
+++ b/rpmdb-rebuild.service
@@ -1,19 +1,19 @@
 [Unit]
 Description=RPM database rebuild
-ConditionPathExists=/var/lib/rpm/.rebuilddb
+ConditionPathExists=/usr/lib/sysimage/rpm/.rebuilddb
 
 # This should run before any daemons that may open the rpmdb
 DefaultDependencies=no
 After=sysinit.target
 Before=basic.target shutdown.target
 Conflicts=shutdown.target
-# In case /var is remote-mounted
-RequiresMountsFor=/var
+# In case /usr is remote-mounted
+RequiresMountsFor=/usr
 
 [Service]
 Type=oneshot
 ExecStart=/usr/bin/rpmdb --rebuilddb
-ExecStartPost=rm -f /var/lib/rpm/.rebuilddb
+ExecStartPost=rm -f /usr/lib/sysimage/rpm/.rebuilddb
 
 [Install]
 WantedBy=basic.target

diff --git a/rpmdb_migrate b/rpmdb_migrate
new file mode 100644
index 0000000..196744d
--- /dev/null
+++ b/rpmdb_migrate
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Script to migrate rpmdb from /var/lib/rpm to new rpmdb path in /usr
+
+# Copyright (C) 2022 Neal Gompa <ngompa@fedoraproject.org>.
+#
+# Fedora-License-Identifier: GPLv2+
+# SPDX-2.0-License-Identifier: GPL-2.0+
+# SPDX-3.0-License-Identifier: GPL-2.0-or-later
+#
+# This program is free software.
+# For more information on the license, see COPYING or
+# <https://www.gnu.org/licenses/gpl-2.0.en.html>.
+# For more information on free software, see
+# <https://www.gnu.org/philosophy/free-sw.en.html>.
+
+
+set -euo pipefail
+
+# Script to migrate the rpmdb to /usr
+rpmdb_path="$(rpm --eval '%_dbpath')"
+rpmdb_path_old="/var/lib/rpm"
+rpmdb_path_new="${rpmdb_path}"
+
+
+if [ "${rpmdb_path}" = "${rpmdb_path_old}" ]; then
+	echo "The rpmdb path is still in /var, exiting!"
+	exit 0
+fi
+
+if [ -L "${rpmdb_path_old}" ]; then
+	echo "The rpmdb has already been migrated, exiting!"
+	rm -v "${rpmdb_path_old}/.migratedb"
+	exit 0
+fi
+
+rpm --verbose --rebuilddb
+
+rm -rfv ${rpmdb_path_old}
+
+ln -srv ${rpmdb_path_new} ${rpmdb_path_old}

                 reply	other threads:[~2026-11-23  9:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179542644771.1.4238654513481584042.rpms-rpm-0b9f813cd529@fedoraproject.org \
    --to=ngompa@fedoraproject.org \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox