git: 6207325f3aac - main - release: Made it possible to specify more attributes in metalog entries

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 11 Sep 2025 13:06:53 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6207325f3aac067fb16f0aa42012302014035ebf

commit 6207325f3aac067fb16f0aa42012302014035ebf
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-09-11 13:05:13 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-09-11 13:05:13 +0000

    release: Made it possible to specify more attributes in metalog entries
    
    Verify that the target file or directory exists, and add support for an
    optional mode.  This is required to enable NO_ROOT builds of some
    cloudware image types.  No functional change intended.
    
    Reviewed by:    cperciva, emaste
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D52449
---
 release/tools/vmimage.subr | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/release/tools/vmimage.subr b/release/tools/vmimage.subr
index 20ffe3b2dac7..32eec6f220e7 100644
--- a/release/tools/vmimage.subr
+++ b/release/tools/vmimage.subr
@@ -39,8 +39,21 @@ cleanup() {
 }
 
 metalog_add_data() {
+	local file mode type
+
 	if [ -n "${NO_ROOT}" ]; then
-		echo "$1 type=file uname=root gname=wheel mode=0644" >> \
+		file=$1
+		if [ -f ${DESTDIR}/${file} ]; then
+			type=file
+			mode=${2:-0644}
+		elif [ -d ${DESTDIR}/${file} ]; then
+			type=dir
+			mode=${2:-0755}
+		else
+			echo "metalog_add_data: ${file} not found" >&2
+			return 1
+		fi
+		echo "${file} type=${type} uname=root gname=wheel mode=${mode}" >> \
 		    ${DESTDIR}/METALOG
 	fi
 }