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).