1
0
Fork 0
mirror of synced 2024-12-13 02:45:45 -05:00

Write template result to temporary file and move

This prevents problems with programs which watch the file for changes and will
first be presented an empty file.
One such example which will show a notification message about an empty config
file is Alacritty.
By writing to a tempory file and then moving it (atomically?) to the real
location this problem is mitigated.
This commit is contained in:
jonasc 2019-02-09 15:38:14 +01:00 committed by Tim Byrne
parent 09a018ea5a
commit a1845c6e8a
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12

4
yadm
View file

@ -208,6 +208,7 @@ function alt() {
#; loop over all "tracked" files
#; for every file which is a *##yadm.j2 create a real file
local temp="$(mktemp)"
local IFS=$'\n'
local match="^(.+)##yadm\\.j2$"
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do
@ -223,7 +224,8 @@ function alt() {
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
YADM_DISTRO=$(query_distro) \
"$ENVTPL_PROGRAM" < "$tracked_file" > "$real_file"
"$ENVTPL_PROGRAM" < "$tracked_file" > "$temp"
mv "$temp" "$real_file"
else
debug "envtpl not available, not creating $real_file from template $tracked_file"
[ -n "$loud" ] && echo "envtpl not available, not creating $real_file from template $tracked_file"