Skip to content

Commit

Permalink
fix: warn if plugin does not support keeping downloads if configured (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jan 9, 2024
1 parent 240a5fb commit 19515ed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
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

0 comments on commit 19515ed

Please sign in to comment.