jw-pkg: Fix ignored target file metadata

During an invokation owner, group and mode definitions of one target file could
leak into another.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2024-07-05 11:20:55 +00:00
commit 8702a63323

View file

@ -272,13 +272,17 @@ cmd_rm_template_output()
cmd_compile_templates()
{
__md() {
stat --format '%U:%G %a' "$1" 2>/dev/null
}
local ext_from="$template_exts" # TODO: support more than one
local ext_from_re=`echo $template_exts | sed 's/\./\\./g'`
local ext_to=""
local ext_tables="$table_exts"
local group=root
local owner=root
local mode=600
local default_group=root
local default_owner=root
local default_mode=600
local conf_patt="^[ ]*# *conf:"
local missing_table=0
local backup=0
@ -288,15 +292,15 @@ cmd_compile_templates()
while [ "${1:0:1}" = '-' ]; do
case "$1" in
-o)
owner="$2"
default_owner="$2"
shift
;;
-m)
mode="$2"
default_mode="$2"
shift
;;
-g)
group="$2"
default_group="$2"
shift
;;
-b)
@ -328,12 +332,20 @@ cmd_compile_templates()
# TODO: use mktemp -d and keep temporary files in read-only dir
local tmp=$to.tmp
log -n "Applying macros in $table to $f"
local mode=$default_mode
local owner=$default_owner
local group=$default_group
local diff=""
eval `sed "/$conf_patt/ !d; s/$conf_patt//" $table`
sed 's|^[ ]*#.*||; s|/|\\/|g; s|\([^ =]\+\)[ =]\+\(.*\)|s/\1/\2/g|' $table | sed -f - $f > $tmp
chmod $mode $tmp
chown $owner $tmp
chgrp $group $tmp
if diff -q $tmp $to >/dev/null 2>&1 && [ "$(stat --format '%u:%g:%A' $to)" = "$(stat --format '%u:%g:%A' $tmp)" ]; then
diff -q $tmp $to >/dev/null 2>&1 || diff="@content"
local md_to=$(__md "$to")
local md_tmp=$(__md "$tmp")
[ "$md_to" = "$md_tmp" ] || diff="$diff@metadata ($md_to -> $md_tmp)"
if [ -z "$diff" ]; then
log -c ", no changes."
rm $tmp
continue
@ -344,7 +356,8 @@ cmd_compile_templates()
cp -p $to $bak
fi
mv $tmp $to
log -c ", done."
diff=${diff##@}
log -c ", updating ${diff//@/ + }, done."
done <<< $(cmd_list_templates "$@")
if [ "$missing_table" != 0 ]; then