From a1845c6e8a1252421f5a249b8a59a4bdceff528f Mon Sep 17 00:00:00 2001 From: jonasc Date: Sat, 9 Feb 2019 15:38:14 +0100 Subject: [PATCH] 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. --- yadm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yadm b/yadm index e55a287..8dc6f4a 100755 --- a/yadm +++ b/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"