From 470480990745e4ed66b6dae303ede987ab508346 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Fri, 5 Jan 2024 22:18:26 +0100 Subject: [PATCH] attempt to solve /usr/sbin upgrade error when owning directory to symlink [release 2.3-10mamba;Tue Sep 05 2023] --- filesystem.spec | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/filesystem.spec b/filesystem.spec index 4e8ff93..e7901c4 100644 --- a/filesystem.spec +++ b/filesystem.spec @@ -2,7 +2,7 @@ Name: filesystem Version: 2.3 -Release: 9mamba +Release: 10mamba Summary: The basic directory layout for a Linux system Group: System/Configuration Vendor: openmamba @@ -78,6 +78,35 @@ ln -s ../run %{buildroot}/var/run #%pre #[ -L /usr/local/man ] && rm -f /usr/local/man || : +%pretrans -p +-- Remove /usr/sbin early to avoid error due to package upgrade from owned dir to symlink +path = "/usr/sbin" +st = posix.stat(path) +if st and st.type == "directory" then + status = os.rename(path, path .. ".rpmmoved") + if not status then + suffix = 0 + while not status do + suffix = suffix + 1 + status = os.rename(path .. ".rpmmoved", path .. ".rpmmoved." .. suffix) + end + os.rename(path, path .. ".rpmmoved") + end +end +path = "/usr/local/sbin" +st = posix.stat(path) +if st and st.type == "directory" then + status = os.rename(path, path .. ".rpmmoved") + if not status then + suffix = 0 + while not status do + suffix = suffix + 1 + status = os.rename(path .. ".rpmmoved", path .. ".rpmmoved." .. suffix) + end + os.rename(path, path .. ".rpmmoved") + end +end + %pre [ -L /var/run ] || { # /var/run -> /run migration @@ -88,18 +117,18 @@ ln -s ../run %{buildroot}/var/run done } # /usr/sbin -> /usr/bin merge -[ -L /usr/sbin ] || { +[ -e /usr/sbin.rpmmoved ] && { echo "Migrating /usr/sbin to /usr/bin..." for d in /usr/sbin /usr/local/sbin; do - for f in $d/*; do - dest=${d/sbin/bin}/`basename $f` - if [ -e $dest ]; then + for f in $d.rpmmoved/*; do + dest="${d/sbin/bin}/`basename $f`" + if [ -e "$dest" ]; then #echo "$f exists as $dest" if [ -L $f ]; then linkdest=`readlink $f` #echo "$f is a symlink to $linkdest" /usr/bin/rm -f $f - elif [ -L $dest ]; then + elif [ -L "$dest" ]; then linkdest=`readlink $dest` #echo "$dest is a symlink to $linkdest" /usr/bin/rm -f $dest && mv $f $dest @@ -108,7 +137,7 @@ ln -s ../run %{buildroot}/var/run /usr/bin/rm -f $f fi else - if [ -L $f ]; then + if [ -L "$f" ]; then linkdest=`readlink $f` if [ "${linkdest:0:3}" = "../" ]; then fulllinkdest=`readlink -f $f` @@ -123,7 +152,7 @@ ln -s ../run %{buildroot}/var/run fi fi done - /usr/bin/rmdir $d || /usr/bin/mv $d $d.notmigrated + /usr/bin/rmdir $d.rpmmoved || /usr/bin/mv $d.rpmmoved $d.notmigrated /usr/bin/ln -s bin $d done } @@ -295,6 +324,9 @@ fi /usr/tmp %changelog +* Tue Sep 05 2023 Silvan Calarco 2.3-10mamba +- attempt to solve /usr/sbin upgrade error when owning directory to symlink + * Mon Sep 04 2023 Silvan Calarco 2.3-9mamba - own lib and lib64 dirs and symlinks