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:
parent
09a018ea5a
commit
a1845c6e8a
1 changed files with 3 additions and 1 deletions
4
yadm
4
yadm
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue