fix: no longer write temporary files to home directory (#1592)

This commit is contained in:
Edwin Kofler 2023-07-26 04:57:06 -07:00 committed by GitHub
parent 299dc97a5b
commit 624604a862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"