diff --git a/lib/functions/installs.bash b/lib/functions/installs.bash index 721ae50c..036c1dab 100644 --- a/lib/functions/installs.bash +++ b/lib/functions/installs.bash @@ -236,8 +236,13 @@ install_tool_version() { 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 always_keep_download=$(get_asdf_config_value "always_keep_download") - if [ ! "$keep_download" = "true" ] && [ ! "$always_keep_download" = "yes" ] && [ -d "$download_path" ]; then - rm -r "$download_path" + if [ ! "$keep_download" = "true" ] && [ ! "$always_keep_download" = "yes" ]; then + if [ -d "$download_path" ]; then + rm -r "$download_path" + else + 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 fi reshim_command "$plugin_name" "$full_version" diff --git a/test/fixtures/dummy_plugin_no_download/LICENSE b/test/fixtures/dummy_plugin_no_download/LICENSE new file mode 100644 index 00000000..d3084751 --- /dev/null +++ b/test/fixtures/dummy_plugin_no_download/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 Akash Manohar J + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/test/fixtures/dummy_plugin_no_download/bin/install b/test/fixtures/dummy_plugin_no_download/bin/install new file mode 100755 index 00000000..4c5589ec --- /dev/null +++ b/test/fixtures/dummy_plugin_no_download/bin/install @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +printf '%s' 'install' diff --git a/test/install_command.bats b/test/install_command.bats index bd945cbe..9e70d544 100644 --- a/test/install_command.bats +++ b/test/install_command.bats @@ -242,9 +242,9 @@ EOM echo 'legacy_version_file = yes' >"$HOME/.asdfrc" echo '1.2.0' >>"$PROJECT_DIR/.dummy-version" cd "$PROJECT_DIR" + run asdf install [ "$status" -eq 0 ] - [ -z "$output" ] [ -f "$ASDF_DIR/installs/dummy/1.2.0/version" ] } @@ -257,7 +257,6 @@ EOM run asdf install [ "$status" -eq 0 ] - [ -z "$output" ] [ -f "$ASDF_DIR/installs/dummy/1.2.0/version" ] } @@ -302,3 +301,12 @@ EOM [ ! -d "$ASDF_DIR/installs/dummy-broken/1.1.0" ] [ "$output" = "Download failed!" ] } + +@test "install_command prints info message if plugin does not support preserving download data if configured" { + install_dummy_plugin_no_download + + run asdf install dummy-no-download 1.0.0 + [ "$status" -eq 0 ] + + [[ "$output" == *'asdf: Warn:'*'not be preserved'* ]] +} diff --git a/test/test_helpers.bash b/test/test_helpers.bash index 103da76c..6f4468e1 100644 --- a/test/test_helpers.bash +++ b/test/test_helpers.bash @@ -30,6 +30,12 @@ install_mock_plugin() { cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin" "$location/plugins/$plugin_name" } +install_mock_plugin_no_download() { + local plugin_name=$1 + local location="${2:-$ASDF_DIR}" + cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin_no_download" "$location/plugins/$plugin_name" +} + install_mock_legacy_plugin() { local plugin_name=$1 local location="${2:-$ASDF_DIR}" @@ -64,6 +70,10 @@ install_dummy_plugin() { install_mock_plugin "dummy" } +install_dummy_plugin_no_download() { + install_mock_plugin_no_download "dummy-no-download" "$1" +} + install_dummy_legacy_plugin() { install_mock_legacy_plugin "legacy-dummy" }