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).
This commit is contained in:
lotherk committed 2026-11-22 18:06:47 +00:00
1 parent c5b90ef7ad
commit 691bf6e543
1 file changed
+20
+20
View File
@@ -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