pkgchroot: force deinstalls, and `mount' keeps its mounts

Two bugs, both measured on 2026-11-22 while rebuilding wm/mcde:

1. `force' ran `clean' + `reinstall'.  reinstall is `install-clean
   install' (mk/install/deinstall.mk:50) and install-clean only removes
   state files, it does not deinstall.  So pkg_add saw the package
   already recorded, refused with "package `mcde-0.1.0' already
   recorded as installed" and returned 0 -- the sysroot kept the
   pre-fix binaries: dtphoto stayed at 15:15 while the binary package
   carried the 21:28 build.  pkgsrc documents the way itself in
   mk/install/install.mk:225: `make deinstall reinstall'.  `deinstall
   || true' because the package may not be installed yet.

2. sandbox_mount set `trap umount_all EXIT INT TERM HUP', so the
   `mount' subcommand unmounted everything again before the caller
   could use it, and still printed "pkgchroot: mounted".  The trap
   belongs to the modes that mount and work: build and force.

Test: `pkgchroot.sh mount' leaves 5 mounts standing and
/mnt/pkgsrc/wm/mcde is visible in the chroot; `pkgchroot.sh umount'
brings it back to 0.  `deinstall' in the chroot removed
/usr/pkg/dt/bin/dtphoto and deregistered mcde-0.1.0.
This commit is contained in:
lotherk committed 2026-11-22 21:56:11 +00:00
1 parent 15e7ca0349
commit a537a3b57d
1 file changed
+3 -1
+3 -1
View File
@@ -64,7 +64,6 @@ sandbox_mount()
mount -t null "$TOP/pkgsrc" "$MNT/pkgsrc"
mount | grep -q " on $MNT/distfiles " ||
mount -t null "${DISTFILES:-$TOP/distfiles}" "$MNT/distfiles"
trap 'umount_all' EXIT INT TERM HUP
mount | grep -q " on $MNT/work " ||
mount -t null "$SB/work" "$MNT/work"
# the binary packages go where the cross build puts them, so tools/make_repo
@@ -144,6 +143,7 @@ mount) sandbox_mount; echo "pkgchroot: mounted" ;;
build)
shift
sandbox_mount
trap 'umount_all' EXIT INT TERM HUP
for p in "$@"; do
echo "=== pkgchroot: $p"
sandbox_run "$p" install
@@ -158,9 +158,11 @@ force)
# Settings change went into no build at all)
shift
sandbox_mount
trap 'umount_all' EXIT INT TERM HUP
for p in "$@"; do
echo "=== pkgchroot (force): $p"
sandbox_run "$p" clean
sandbox_run "$p" deinstall || true
sandbox_run "$p" reinstall
done
sandbox_clean