diff --git a/tools/pkgchroot.sh b/tools/pkgchroot.sh index e2e2ceae19..55ae3c2fc0 100755 --- a/tools/pkgchroot.sh +++ b/tools/pkgchroot.sh @@ -71,6 +71,26 @@ sandbox_mount() # and the sysinst repository see one directory on either host mount | grep -q " on $MNT/packages " || mount -t null "$TOP/build/packages" "$MNT/packages" + # The file index beside the package database is a cache, and pkg_add + # trusts it blindly: after a `force' run removed packages, the index still + # named digest-20220214 as the owner of /usr/pkg/bin/digest -- a package + # that was not registered and a file that did not exist. pkg_add then + # reported "digest-20220214: conflicting PLIST with digest-20220214" when + # bootstrapping digest itself, and every build that needed a tool from the + # sysroot stopped (measured 2026-11-22: tools/pkgchroot.sh force wm/mcde + # left 45 packages deleted and could not reinstall any of them). + sandbox_index +} + +# Rebuild the by-file index from the +CONTENTS of the installed packages, so it +# can only name packages that are registered. pkg_admin lives in the sysroot +# (/usr/sbin, part of a base set since the package tools moved there); the +# sysroot's own copy is used so the index format matches the pkg_add inside. +sandbox_index() +{ + [ -x "$D/usr/sbin/pkg_admin" ] || return 0 + chroot "$D" /usr/sbin/pkg_admin -K /usr/pkg/pkgdb rebuild >/dev/null 2>&1 || + echo "pkgchroot: rebuild of pkgdb.byfile.db failed" >&2 } # The base bmake does not read MAKECONF, and a mk.conf in the sysroot's /etc