From 67e57f73f195c6c769ef86adf00d3a5413ab739f Mon Sep 17 00:00:00 2001 From: Mazen Harake Date: Wed, 20 Jul 2016 14:40:57 +0200 Subject: Disallow installations to previously installed locations --- kerl | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'kerl') diff --git a/kerl b/kerl index 5f5d5b7..74df2d1 100755 --- a/kerl +++ b/kerl @@ -1009,20 +1009,26 @@ is_valid_install_path() return 1 fi + INSTALLED_NAME=$(get_name_from_install_path $candidate) + if [ -n "$INSTALLED_NAME" ]; then + echo "ERROR: Installation ($INSTALLED_NAME) already registered for this location ($1)" + return 1 + fi + # if the install directory exists, # do not allow installs into a directory # that is not empty if [ -e "$1" ]; then - if [ -d "$1" ]; then - count=$(ls -la "$1" | wc -l) - if [ $count -ne 3 ]; then - echo "ERROR: $1 does not appear to be an empty directory." - return 1 - fi - else - echo "ERROR: $1 is not a directory." - return 1 - fi + if [ -d "$1" ]; then + count=$(ls -la "$1" | wc -l) + if [ $count -ne 3 ]; then + echo "ERROR: $1 does not appear to be an empty directory." + return 1 + fi + else + echo "ERROR: $1 is not a directory." + return 1 + fi fi return 0 @@ -1122,7 +1128,7 @@ get_active_path() get_name_from_install_path() { if [ -f "$KERL_BASE_DIR"/otp_installations ]; then - grep -E "$1$" "$KERL_BASE_DIR"/otp_installations | cut -d' ' -f1 + grep -m1 -E "$1$" "$KERL_BASE_DIR"/otp_installations | cut -d' ' -f1 fi return 0 } -- cgit v1.2.3