Skip to content

Commit

Permalink
fix: No longer write temporary files to home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jul 11, 2023
1 parent d1a563d commit 1e64304
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/functions/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1e64304

Please sign in to comment.