From 80f25ad381e93e58d4fba7d1cc572ac7f4d32f63 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Thu, 21 Sep 2023 08:45:24 +0200 Subject: [PATCH] (tue-env) check if evironment dir exists when removing --- setup/tue-env.bash | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/setup/tue-env.bash b/setup/tue-env.bash index 26a48262f..fb5ec1235 100644 --- a/setup/tue-env.bash +++ b/setup/tue-env.bash @@ -119,18 +119,25 @@ options: dir=$(cat "$TUE_DIR"/user/envs/"$env") rm "$TUE_DIR"/user/envs/"$env" - if [ $PURGE == "false" ] + if [[ -d ${dir} ]] then - dir_moved=$dir.$(date +%F_%R) - mv "$dir" "$dir_moved" - # shellcheck disable=SC1078,SC1079 - echo """[tue-env] Removed environment '$env' -Moved environment directory of '$env' to '$dir_moved'""" + if [ $PURGE == "false" ] + then + dir_moved=$dir.$(date +%F_%R) + mv "${dir}" "${dir_moved}" + # shellcheck disable=SC1078,SC1079 + echo """[tue-env] Removed environment '${env}' +Moved environment directory from '${dir}' to '${dir_moved}'""" + else + rm -rf "${dir}" + # shellcheck disable=SC1078,SC1079 + echo """[tue-env] Removed environment '$env' +Purged environment directory '${dir}'""" + fi else - rm -rf "$dir" # shellcheck disable=SC1078,SC1079 - echo """[tue-env] Removed environment '$env' -Purged environment directory of '$env'""" + echo """[tue-env] Removed environment '${env}' +Environment directory '${dir}' didn't exist (anymore)""" fi elif [[ $cmd == "switch" ]]