Control: tags -1 patch

The attached patch, against 1:3.2.4~rc1-3.5, fixes the check itself rather
than turning Tiger_DPKG_Optimize off.

Two things went wrong on a merged-/usr system:

1. deb_nopackfiles tests "[ ! -L $dir ]" with dirlist entries like "/bin/".
With the trailing slash the test follows the symlink, so /bin, /sbin and
/lib were scanned as well, and /lib brought in all of /usr/lib, which the
check deliberately leaves out. On a Linux Mint 22.3 desktop that was 33,230
lin001w warnings.

2. dpkg records some files under /bin and others under /usr/bin, so a path
found under /usr/bin can be listed under /bin in the .list file. The
optimised lookup now rewrites both the package lists and the diversions to
the /usr form (only when /bin, /sbin, /lib are symlinks), and the dpkg -S
path retries without /usr.

Tested in fresh debian:sid, debian:stable and ubuntu:24.04 containers with
one binary modified, one deleted and one stray file added to /usr/sbin:
before, 3,210 lin001w warnings; after, two (the stray file and Docker's own
/usr/sbin/policy-rc.d). The patch is for systems/Linux/2; Linux/3 and
Linux/4 are copies of it in the Debian source.

Andrei Trimbitas

--- a/systems/Linux/2/deb_nopackfiles
+++ b/systems/Linux/2/deb_nopackfiles
@@ -17,6 +17,11 @@
#
# Linux/deb_nopackfiles - 23/08/2001
#
+# 10/04/2026 - atrimbitas - Support merged-/usr systems (Debian bug
#1111306).
+# Test the directory itself for a symlink, since '/bin/' with
+# a trailing slash resolves the link and /lib then pulled in
+# all of /usr/lib. dpkg may record a file under /bin, /sbin or
+# /lib or under /usr, so both forms count as owned.
# 05/07/2006 - jfs - Skip directories that are symbolic links, this happens
# with /usr/X11R6/bin as the latest Xorg package
# versions just symlink this to /usr/bin/ (Debian bug #367931)
@@ -45,7 +50,7 @@
# - Consider the use of 'dlocate' which will be faster than DPKG. Notice
# however that it's priority "optional"
# dlocate could be faster
-# DLOCATE=`which dlocate`
+# DLOCATE=`command -v dlocate`
# DLOCATE=${DLOCATE:-$DPKG}
#
#-----------------------------------------------------------------------------
@@ -108,8 +113,8 @@
haveallcmds DPKG || exit 1
fi

-safe_temp $WORKDIR/dpkg-packages.list
-trap 'delete $WORKDIR/dpkg-packages.list ; exit 1' 1 2 3 15
+safe_temp $WORKDIR/dpkg-packages.list $WORKDIR/dpkg-diversions.list
+trap 'delete $WORKDIR/dpkg-packages.list $WORKDIR/dpkg-diversions.list ;
exit 1' 1 2 3 15

# NOTE: /usr/lib cannot be added here since quite a lot of packages
# will compile stuff there on installation which will result in a
@@ -118,7 +123,7 @@
okdirs=""
# Before using dirlist we are going to determine which values are ok
for dir in $dirlist ; do
- if [ -d $dir ] && [ ! -L $dir ] ; then
+ if [ -d $dir ] && [ ! -L "${dir%/}" ] ; then
if [ -n "$okdirs" ] ; then
okdirs="$dir $okdirs"
else
@@ -141,6 +146,9 @@
while read file
do
pack=`$DPKG -S $file 2>/dev/null`
+ # On merged-/usr systems dpkg may record the file under /bin, /sbin or
/lib
+ [ "$pack" = "" ] && [ "${file#/usr/}" != "$file" ] &&
+ pack=`$DPKG -S ${file#/usr} 2>/dev/null`
[ "$pack" = "" ] && {
message WARN lin001w "" "File \`$file' does not belong to any package."
}
@@ -148,18 +156,25 @@
else
# Alternative (optimal but not following standard way)
seddirlist=`echo $dirlist | $SED -e 's/ /\\\\\|/g; s/\//\\\\\//g'`
+ # On merged-/usr systems /bin, /sbin and /lib link into /usr and dpkg
+ # may record a file under either path, so rewrite them to /usr
+ usrmerge=
+ for dir in bin sbin lib ; do
+ [ -L /$dir ] && usrmerge="$usrmerge -e s,^/$dir/,/usr/$dir/,"
+ done
$FIND /var/lib/dpkg/info -name "*.list" -exec cat {} \; |
- $SED -ne "/^\($seddirlist\)/p" > $WORKDIR/dpkg-packages.list
+ $SED -n $usrmerge -e "/^\($seddirlist\)/p" > $WORKDIR/dpkg-packages.list
+ $SED -e '' $usrmerge /var/lib/dpkg/diversions >
$WORKDIR/dpkg-diversions.list
$FIND $dirlist -type f 2>/dev/null |
# We are not using -maxdepth here, but we could...
$GREP -x -F -v -f $WORKDIR/dpkg-packages.list |
# To search for diversions
- $GREP -x -F -v -f /var/lib/dpkg/diversions |
+ $GREP -x -F -v -f $WORKDIR/dpkg-diversions.list |
while read file
do
message WARN lin001w "" "File \`$file' does not belong to any package."
done
- delete $WORKDIR/dpkg-packages.list
+ delete $WORKDIR/dpkg-packages.list $WORKDIR/dpkg-diversions.list
fi

exit 0

Reply via email to