Skip to content

Commit

Permalink
Trap sigint when installing plugins, fix #214
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Jul 30, 2017
1 parent 242d132 commit 1499bda
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/commands/install.sh
@@ -1,3 +1,15 @@
handle_failure() {
local install_path="$1"
rm -rf "$install_path"
exit 1
}

handle_cancel() {
local install_path="$1"
echo -e "\nreceived sigint, cleaning up"
handle_failure "$install_path"
}

install_command() {
local plugin_name=$1
local full_version=$2
Expand Down Expand Up @@ -64,24 +76,25 @@ install_tool_version() {

local install_path=$(get_install_path $plugin_name $install_type $version)
local concurrency=$(get_concurrency)
if [ -d $install_path ]; then
trap 'handle_cancel $install_path' INT

if [ -d "$install_path" ]; then
echo "$plugin_name $full_version is already installed"
else
(
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
export ASDF_CONCURRENCY=$concurrency
mkdir $install_path
bash ${plugin_path}/bin/install
mkdir "$install_path"
bash "${plugin_path}"/bin/install
)

local exit_code=$?
if [ $exit_code -eq 0 ]; then
reshim_command $plugin_name $full_version
else
rm -rf $install_path
exit 1
handle_failure
fi
fi
}

0 comments on commit 1499bda

Please sign in to comment.