Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Print warning if plugin does not support keeping downloads, if configured #1644

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/functions/installs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/dummy_plugin_no_download/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions test/fixtures/dummy_plugin_no_download/bin/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

printf '%s' 'install'
12 changes: 10 additions & 2 deletions test/install_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}

Expand All @@ -257,7 +257,6 @@ EOM

run asdf install
[ "$status" -eq 0 ]
[ -z "$output" ]
[ -f "$ASDF_DIR/installs/dummy/1.2.0/version" ]
}

Expand Down Expand Up @@ -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'* ]]
}
10 changes: 10 additions & 0 deletions test/test_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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"
}
Expand Down