Skip to content

Commit

Permalink
fix: Only display the "can't keep downloads" warning when asked to ke…
Browse files Browse the repository at this point in the history
…ep downloads (#1756)
  • Loading branch information
benblank authored Aug 15, 2024
1 parent ccdd47d commit 44f3efb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/functions/installs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,16 @@ install_tool_version() {

local install_exit_code=$?
if [ $install_exit_code -eq 0 ] && [ $download_exit_code -eq 0 ]; then
# Remove download directory if --keep-download flag or always_keep_download config setting are not set
# If the download directory should be kept, but isn't available, warn the user
always_keep_download=$(get_asdf_config_value "always_keep_download")
if [ ! "$keep_download" = "true" ] && [ ! "$always_keep_download" = "yes" ]; then
if [ -d "$download_path" ]; then
rm -r "$download_path"
else
if [ "$keep_download" = "true" ] || [ "$always_keep_download" = "yes" ]; then
if [ ! -d "$download_path" ]; then
printf '%s\n' "asdf: Warn: You have configured asdf to preserve downloaded files (with always_keep_download=yes or --keep-download). But" >&2
printf '%s\n' "asdf: Warn: the current plugin ($plugin_name) does not support that. Downloaded files will not be preserved." >&2
fi
# Otherwise, remove the download directory if it exists
elif [ -d "$download_path" ]; then
rm -r "$download_path"
fi

reshim_command "$plugin_name" "$full_version"
Expand Down
18 changes: 16 additions & 2 deletions test/install_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ setup() {
install_dummy_legacy_plugin
install_dummy_plugin
install_dummy_broken_plugin
install_dummy_plugin_no_download

PROJECT_DIR="$HOME/project"
mkdir -p "$PROJECT_DIR"
Expand Down Expand Up @@ -302,11 +303,24 @@ EOM
[ "$output" = "Download failed!" ]
}

@test "install_command prints info message if plugin does not support preserving download data if configured" {
install_dummy_plugin_no_download
@test "install_command prints info message if plugin does not support preserving download data if --keep-download flag is provided" {
run asdf install dummy-no-download 1.0.0 --keep-download
[ "$status" -eq 0 ]

[[ "$output" == *'asdf: Warn:'*'not be preserved'* ]]
}

@test "install_command prints info message if plugin does not support preserving download data if always_keep_download setting is true" {
echo 'always_keep_download = yes' >"$HOME/.asdfrc"
run asdf install dummy-no-download 1.0.0
[ "$status" -eq 0 ]

[[ "$output" == *'asdf: Warn:'*'not be preserved'* ]]
}

@test "install_command does not print info message if --keep-download flag is not provided and always_keep_download setting is false" {
run asdf install dummy-no-download 1.0.0
[ "$status" -eq 0 ]

[[ "$output" != *'asdf: Warn:'*'not be preserved'* ]]
}

0 comments on commit 44f3efb

Please sign in to comment.