The branch main has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=4f7336a93cb84a0633ca9aa715e474625b4adce5
commit 4f7336a93cb84a0633ca9aa715e474625b4adce5 Author: Xin LI <[email protected]> AuthorDate: 2026-01-29 03:23:15 +0000 Commit: Xin LI <[email protected]> CommitDate: 2026-02-05 03:44:26 +0000 etcupdate: Do not ignore empty files. PR: bin/292773 Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54935 --- usr.sbin/etcupdate/etcupdate.sh | 4 -- usr.sbin/etcupdate/tests/Makefile | 1 + usr.sbin/etcupdate/tests/empty_file_test.sh | 86 +++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/usr.sbin/etcupdate/etcupdate.sh b/usr.sbin/etcupdate/etcupdate.sh index 7bddd6593b56..8f4737136d72 100755 --- a/usr.sbin/etcupdate/etcupdate.sh +++ b/usr.sbin/etcupdate/etcupdate.sh @@ -242,10 +242,6 @@ build_tree() (cd $1 && printf '%s\n' $autogenfiles >> $metatmp && \ rm -f $autogenfiles) || return 1 - # Remove empty files. These just clutter the output of 'diff'. - (cd $1 && find . -type f -size 0 -delete -print >> $metatmp) || \ - return 1 - # Trim empty directories. (cd $1 && find . -depth -type d -empty -delete -print >> $metatmp) || \ return 1 diff --git a/usr.sbin/etcupdate/tests/Makefile b/usr.sbin/etcupdate/tests/Makefile index ba0b6223576b..8dc9bef0eb25 100644 --- a/usr.sbin/etcupdate/tests/Makefile +++ b/usr.sbin/etcupdate/tests/Makefile @@ -1,6 +1,7 @@ PLAIN_TESTS_SH= .for test in always_test \ conflicts_test \ + empty_file_test \ fbsdid_test \ ignore_test \ preworld_test \ diff --git a/usr.sbin/etcupdate/tests/empty_file_test.sh b/usr.sbin/etcupdate/tests/empty_file_test.sh new file mode 100755 index 000000000000..5fe7a5ffb2b3 --- /dev/null +++ b/usr.sbin/etcupdate/tests/empty_file_test.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# Regression test for "etcupdate: Do not ignore empty files" + +FAILED=no +WORKDIR=$(pwd)/work + +usage() +{ + echo "Usage: empty_file_test.sh [-s script] [-w workdir]" + exit 1 +} + +COMMAND=etcupdate +while getopts "s:w:" option; do + case $option in + s) + COMMAND="sh $OPTARG" + ;; + w) + WORKDIR=$OPTARG + ;; + *) + echo + usage + ;; + esac +done +shift $((OPTIND - 1)) +if [ $# -ne 0 ]; then + usage +fi + +SRC=$WORKDIR/src +DEST=$WORKDIR/dest +TEST=$WORKDIR/test + +# Clean up +rm -rf $WORKDIR + +# Create a mock source tree +mkdir -p $SRC +touch $SRC/empty_file + +# Create a mock make script +cat > $WORKDIR/mock_make.sh <<EOF +#!/bin/sh + +# Scan all arguments for targets +for arg in "\$@"; do + case \$arg in + *=*) + # Export variable assignments + export "\$arg" + ;; + distrib-dirs) + if [ -n "\$DESTDIR" ]; then + mkdir -p "\$DESTDIR/etc" + fi + ;; + distribution) + if [ -n "\$DESTDIR" ]; then + cp $SRC/empty_file "\$DESTDIR/etc/empty_file" + echo "./etc/empty_file type=file mode=0644 uname=root gname=wheel" > "\$DESTDIR/METALOG" + fi + ;; + esac +done +exit 0 +EOF +chmod +x $WORKDIR/mock_make.sh + +# Run etcupdate +# Use -B to skip build targets +# Use -N to run without root privileges +# Use 'extract' command to bypass root check in 'update' command +$COMMAND extract -N -B -s $SRC -d $WORKDIR -m $WORKDIR/mock_make.sh > $WORKDIR/test.out 2>&1 + +if [ -f $WORKDIR/current/etc/empty_file ]; then + echo "Empty file preserved." +else + echo "Empty file missing from current tree." + FAILED=yes +fi + +[ "${FAILED}" = no ]
