Create rpm Requires generator

The generator will generate a Requires on filesystem(unmerged-sbin-symlinks),
i.e. effectively on a new-enough version of _this_ package. This is needed to
solve the following problem:

  as packages are rebuilt in a merged-sbin environment, their payload paths
  change from /usr/sbin to /usr/bin. In all the cases where there were other
  packages that dependended on the old paths via explicit Requires, compat
  Provides on the old path was added along with
  Requires:filesystem(unmerged-sbin-symlinks). This means that those packages
  will not be installed with an older filesystem.rpm. But for packages that
  didn't need this special treatment, no dependency is generated. When they
  are installed into an upgraded environment which still has split-sbin and
  has an older copy of filesystem, the file is moved without the compat
  symlink being created. Thus, any scripts, or systemd service files, etc.,
  referring to the old path are now broken. We need to require a new-enough
  filesystem.rpm to be installed so avoid breakage on such partially upgraded
  systems.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-07-13 16:31:28 +02:00
parent 644bd3496d
commit 898835da98
4 changed files with 61 additions and 1 deletions

3
filesystem.attr Normal file
View File

@ -0,0 +1,3 @@
%__filesystem_requires %{_rpmconfigdir}/filesystem.req %{_datadir}/filesystem/sbin-filenames
%__filesystem_protocol multifile
%__filesystem_path ^(/usr)?/bin/.*$

18
filesystem.req Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/bash
# Generate Requires: filesystem(unmerged-sbin-symlinks) if any
# of the filenames were known to reside in /usr/sbin.
# When the package with the files is being built, it's possible that
# %_sbindir==/usr/bin, so we cannot rely on the location to figure
# this out and we need a hardcoded list.
sbin_filenames=${1:?}
declare -A "filenames=($(sed 's/.*/["\0"]=1/' <"${sbin_filenames}"))"
while read -r path; do
filename="$(basename "$path")"
if [ -n "${filenames[$filename]}" ]; then
echo ";$path"
echo "filesystem(unmerged-sbin-symlinks)"
fi
done

View File

@ -10,6 +10,9 @@ Source1: https://pagure.io/filesystem/raw/master/f/lang-exceptions
Source2: iso_639.sed
Source3: iso_3166.sed
Source4: sbin-filenames
Source5: filesystem.attr
Source6: filesystem.req
Source7: macros.filesystem
BuildRequires: iso-codes
Requires(pre): setup
@ -46,6 +49,14 @@ This subpackage of filesystem package contains just the file with
the directories owned by the filesystem package. This can be used
during the build process instead of calling rpm -ql filesystem.
%package srpm-macros
Summary: Macros for the sbin-merge
License: Public Domain
%description srpm-macros
This subpackage of filesystem package contains rpm macro definitions
and an rpm attribute geneator.
%prep
rm -f $RPM_BUILD_DIR/filelist
@ -147,11 +158,18 @@ for i in man{1,2,3,4,5,6,7,8,9,n,1x,2x,3x,4x,5x,6x,7x,8x,9x,0p,1p,3p}; do
echo "/usr/share/man/$i" >>$RPM_BUILD_DIR/filelist
done
mkdir -p %{buildroot}/usr/share/filesystem
mkdir -p %{buildroot}%{_datadir}/filesystem
#find all dirs in the buildroot owned by filesystem and store them
find %{buildroot} -mindepth 0 | sed -e 's|%{buildroot}|/|' -e 's|//|/|' \
| LC_ALL=C sort | grep -v filesystem >%{buildroot}%{_datadir}/filesystem/paths
cp -p %{SOURCE4} %{buildroot}%{_datadir}/filesystem/sbin-filenames
mkdir -p %{buildroot}%{_fileattrsdir} %{buildroot}%{_rpmconfigdir} %{buildroot}%{rpmmacrodir}
cp -p %{SOURCE5} %{buildroot}%{_fileattrsdir}/filesystem.attr
cp -p %{SOURCE6} %{buildroot}%{_rpmconfigdir}/filesystem.req
cp -p %{SOURCE7} %{buildroot}%{rpmmacrodir}/macros.filesystem
%pretrans -p <lua>
--# If we are running in pretrans in a fresh root, there is no /usr and
--# symlinks. We cannot be sure, to be the very first rpm in the
@ -366,6 +384,12 @@ end
%dir %{_datadir}/filesystem
%{_datadir}/filesystem/paths
%files srpm-macros
%{_datadir}/filesystem/sbin-filenames
%{_fileattrsdir}/filesystem.attr
%{_rpmconfigdir}/filesystem.req
%{rpmmacrodir}/macros.filesystem
%files -f filelist
%defattr(0755,root,root,0755)
%dir %attr(555,root,root) /

15
macros.filesystem Normal file
View File

@ -0,0 +1,15 @@
# Convenience macro for the transition to merged-sbin
# (https://fedoraproject.org/wiki/Changes/Unify_bin_and_sbin)
# Usage:
# List all files listed in %%files as %%_sbindir/foo.
# Example:
# %%sbin_merge_compat /usr/sbin/foobar
# %%{sbin_merge_compat /usr/sbin/bar1
# /usr/sbin/bar2
# }
%sbin_merge_compat() \
%if "%{_sbindir}" == "%{_bindir}" \
Requires: filesystem(unmerged-sbin-symlinks) \
Provides: %{shrink:%{?*}} \
%endif