git: 7fab248fed5b - stable/15 - vmimage.subr: Include dangling symlinks in images

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Wed, 23 Sep 2026 18:36:55 UTC
The branch stable/15 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=7fab248fed5b001cc2337ff68d0da8efe5c2f8d4

commit 7fab248fed5b001cc2337ff68d0da8efe5c2f8d4
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2026-09-22 00:08:26 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-09-23 18:36:29 +0000

    vmimage.subr: Include dangling symlinks in images
    
    When creating VM images, we filter the METALOG file created by pkg(8)
    when installing non-base packages, rejecting any lines which correspond
    to files which don't exist; this solves a problem which arose when a
    package was installed and then deinstalled (or upgraded) later in the
    image-building process.
    
    Unfortunately [ -e ... ] follows symlinks and is not basedir-aware, so
    an absolute symlink which is valid *inside* the image is omitted from
    the image if it points to something which isn't present in the build
    host system.
    
    Replace [ -e ... ] with [ -e ... ] || [ -L ... ] so that symlinks are
    included even if dangling.
    
    While I'm here, add quoting in case future paths become problematic.
    
    Sponsored by:   Amazon
    MFC after:      3 days
    
    (cherry picked from commit 5a2328a17851ac609ab6c786d9b0db388f15e6b3)
---
 release/tools/vmimage.subr | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/release/tools/vmimage.subr b/release/tools/vmimage.subr
index f06bf4848cb8..b8d2be965dde 100644
--- a/release/tools/vmimage.subr
+++ b/release/tools/vmimage.subr
@@ -266,7 +266,8 @@ buildfs() {
 	# have been logged which no longer exist if a package was removed.
 	if [ -f ${DESTDIR}/METALOG.pkg ]; then
 		while read F REST; do
-			if [ -e ${DESTDIR}/${F} ]; then
+			if [ -e "${DESTDIR}/${F}" ] ||
+			    [ -L "${DESTDIR}/${F}" ]; then
 				echo "${F} ${REST}" >> ${DESTDIR}/METALOG
 			fi
 		done < ${DESTDIR}/METALOG.pkg