Skip to content

Commit e8ea70d

Browse files
author
olevole
committed
sysrc: fix/restore perms for temporary file
1 parent cb8ca98 commit e8ea70d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

share/bsdconfig/sysrc.subr

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ f_sysrc_set()
596596
# return $FAILURE
597597
# fi
598598

599-
local tmpfile="$( mktemp )"
600-
[ "$tmpfile" ] || return $FAILURE
599+
local tmpfile="$( mktemp )"
600+
[ "$tmpfile" ] || return $FAILURE
601601

602602

603603
#
@@ -606,11 +606,30 @@ f_sysrc_set()
606606
# temporary file over the destination, the destination will inherit the
607607
# permissions from the temporary file).
608608
#
609-
# local mode
609+
local mode
610+
local owner
611+
610612
# f_eval_catch -dk mode $funcname stat 'stat -f "%%#Lp" "%s"' "$file" ||
611613
# mode=0644
612614
# f_eval_catch -d $funcname chmod 'chmod "%s" "%s"' "$mode" "$tmpfile"
613615

616+
case $( uname -s ) in
617+
Linux)
618+
mode=$( stat -c "%a" ${file} 2>/dev/null )
619+
owner=$( stat -c "%u:%g" ${file} 2>/dev/null )
620+
;;
621+
*)
622+
mode=$( stat -f "%Lp" ${file} 2>/dev/null )
623+
owner=$( stat -f "%u:%g" ${file} 2>/dev/null )
624+
;;
625+
esac
626+
627+
[ -z "${mode}" ] && mode="0644"
628+
[ -z "${owner}" ] && mode="0:0"
629+
630+
chmod ${mode} ${tmpfile}
631+
chown ${owner} ${tmpfile}
632+
614633
#
615634
# Fixup ownership. The destination file _is_ writable (we tested
616635
# earlier above). However, this will fail if we don't have sufficient

0 commit comments

Comments
 (0)