Source: progress-linux-metapackages
Version: 20221002-20
Severity: serious
Tags: patch
User: helm...@debian.org
Usertags: dep17

Hi,

I'm sorry to tell you that I still got the duplicated diversions wrong.
The full story is at
https://lists.debian.org/debian-devel/2025/01/msg00125.html. In any
case, I managed to reproduce bad scenarios for progress-linux-container
whilst it is not part of bookworm. The main issue here is that --rename
may be specified for the canonicalized diversion when the actual file is
aliased and then it may be renamed in a bad way making dpkg unhappy.
Theoretically (affecting upgrades from bullseye to trixie), the order of
diversions was wrong as diversion targets must not overlap. Adding the
canonicalized diversion was failing as the aliased diversion had not yet
changed its target.

I'm attaching a patch that fixes both and also attaching my test cases
(that are all passing now). I added more comments such that the mess
becomes easier to understand by my future self and others.

Helmut
diff --minimal -Nru progress-linux-metapackages-20221002/debian/changelog 
progress-linux-metapackages-20221002/debian/changelog
--- progress-linux-metapackages-20221002/debian/changelog       2024-12-12 
18:04:29.000000000 +0100
+++ progress-linux-metapackages-20221002/debian/changelog       2025-01-13 
16:34:35.000000000 +0100
@@ -1,3 +1,10 @@
+progress-linux-metapackages (20221002-20.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix --rename flags on duplicated diversions (DEP17 M18, Closes: #-1)
+
+ -- Helmut Grohne <hel...@subdivi.de>  Mon, 13 Jan 2025 16:34:35 +0100
+
 progress-linux-metapackages (20221002-20) sid; urgency=medium
 
   * Uploading to sid.
diff --minimal -Nru 
progress-linux-metapackages-20221002/debian/progress-linux-container.preinst 
progress-linux-metapackages-20221002/debian/progress-linux-container.preinst
--- 
progress-linux-metapackages-20221002/debian/progress-linux-container.preinst    
    2024-12-12 18:01:20.000000000 +0100
+++ 
progress-linux-metapackages-20221002/debian/progress-linux-container.preinst    
    2025-01-13 16:34:31.000000000 +0100
@@ -8,26 +8,22 @@
 
                for FILE in halt poweroff reboot shutdown coldreboot
                do
-                       TRUENAME_USR="$(dpkg-divert --truename 
"/usr/sbin/${FILE}")"
-                       TRUENAME_ALIAS="$(dpkg-divert --truename 
"/sbin/${FILE}")"
+                       # DEP17 M18 duplicated diversion, can be removed after 
trixie.
                        RENAME_FLAG="--no-rename"
+                       TRUENAME_ALIAS="$(dpkg-divert --truename 
"/sbin/${FILE}")"
 
-                       if [ "${TRUENAME_USR}" = "/usr/sbin/${FILE}" ]
+                       if [ "${TRUENAME_ALIAS}" = "/sbin/${FILE}" ]
                        then
-                               if [ "${TRUENAME_ALIAS}" = "/sbin/${FILE}" ]
+                               # Rename if the file is presently installed as 
aliased.
+                               if dpkg -S "/sbin/${FILE}" 2>/dev/null | grep 
-q "^[^ ]*: /sbin/${FILE}\$"
                                then
                                        RENAME_FLAG="--rename"
                                fi
 
-                               dpkg-divert --package progress-linux-container 
--quiet --add "${RENAME_FLAG}" --divert 
"/usr/lib/container/divert/${FILE}.orig" "/usr/sbin/${FILE}"
-                       fi
-
-                       # DEP17 M18 duplicated diversion, can be removed after 
trixie.
-                       if [ "${TRUENAME_ALIAS}" = "/sbin/${FILE}" ]
-                       then
                                dpkg-divert --package progress-linux-container 
--quiet --add "${RENAME_FLAG}" --divert 
"/lib/container/divert/${FILE}.orig.usr-is-merged" "/sbin/${FILE}"
                        elif [ "${TRUENAME_ALIAS}" != 
"/lib/container/divert/${FILE}.orig.usr-is-merged" ]
                        then
+                               # Change the diversion target. Must be done 
before adding the canonicalized diversion below.
                                dpkg-divert --package progress-linux-container 
--quiet --remove --no-rename "/sbin/${FILE}"
                                dpkg-divert --package progress-linux-container 
--quiet --add --no-rename --divert 
"/lib/container/divert/${FILE}.orig.usr-is-merged" "/sbin/${FILE}"
 
@@ -36,6 +32,10 @@
                                        mv "${TRUENAME_ALIAS}" 
"/lib/container/divert/${FILE}.orig.usr-is-merged"
                                fi
                        fi
+
+                       # We may rename unconditionally here. If the file is 
aliased, the earlier --rename will have moved it.
+                       dpkg-divert --package progress-linux-container --quiet 
--add --rename --divert "/usr/lib/container/divert/${FILE}.orig" 
"/usr/sbin/${FILE}"
+
                done
 
                for FILE in pm-hibernate pm-suspend pm-suspend-hybrid
@@ -44,6 +44,7 @@
 
                        if [ "${TRUENAME_USR}" = 
"/lib/container/divert/${FILE}.orig" ]
                        then
+                               # Update diversion target from aliased to 
canonical.
                                dpkg-divert --package progress-linux-container 
--quiet --remove --no-rename "/usr/sbin/${FILE}"
                                dpkg-divert --package progress-linux-container 
--quiet --add --no-rename --divert "/usr/lib/container/divert/${FILE}.orig" 
"/usr/sbin/${FILE}"
                        else

Attachment: test-pl.sh
Description: Bourne shell script

Reply via email to