From 691bf6e543634ca4fe8c078d9d3ada918d3c20d5 Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 18:06:47 +0000 Subject: [PATCH] pkgchroot: the file index is rebuilt before any build The by-file index beside the package database is a cache, and pkg_add trusts it without checking the database: after a `force' run had removed packages, it 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: bin/digest" against itself and would not install the tool, so every build that needed something from the sysroot stopped. Measured 2026-11-22: 45 packages were left deleted, and none of them could be reinstalled. sandbox_index() rebuilds the index from the +CONTENTS of the packages that are registered, so it can only name packages that exist. It runs at the end of sandbox_mount(), before any build starts, and uses the sysroot's own pkg_admin (/usr/sbin: the package tools are part of a base set since they moved there), so the index format matches the pkg_add inside the chroot. Measured: with the stale index, `tools/pkgchroot.sh force pkgtools/digest' failed with the self-conflict above; after `pkg_admin -K ... rebuild' it built and installed (rc=0, 14131 files from 86 packages). --- tools/pkgchroot.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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