From 624604a8626dc6006d78121d4cf0f6c920449c56 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Wed, 26 Jul 2023 04:57:06 -0700 Subject: [PATCH] fix: no longer write temporary files to home directory (#1592) --- lib/functions/versions.bash | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/functions/versions.bash b/lib/functions/versions.bash index e3e873ab..4b7cc34b 100644 --- a/lib/functions/versions.bash +++ b/lib/functions/versions.bash @@ -61,8 +61,15 @@ version_command() { done if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then - sed -i.bak -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$file" - rm -f "$file".bak + local temp_dir + temp_dir=${TMPDIR:-/tmp} + + local temp_tool_versions_file + temp_tool_versions_file=$(mktemp "$temp_dir/asdf-tool-versions-file.XXXXXX") + + cp -f "$file" "$temp_tool_versions_file" + sed -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$temp_tool_versions_file" >"$file" + rm -f "$temp_tool_versions_file" else # Add a trailing newline at the end of the file if missing [[ -f "$file" && -n "$(tail -c1 "$file")" ]] && printf '\n' >>"$file"